Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File.Exists and FileInfo.Exists returning false result

Status
Not open for further replies.

ugagrad

Programmer
Sep 12, 2003
49
US
Hello,
I have two services one I will call "Processor" the other we will call "Communicator". The Processor calls a function on the Communicator which tells it to contact a third party web service. The web service returns a file stream and the Communicator writes the stream to a DFS File System. Then the communicator returns the location of that file to the processor. The problem is that sometimes when the processor calls File.Exists(somefile) it returns false. However, the file is there!. I have tried using FileInfo and calling FileInfo.refresh but I get the same result. I have tried making the processor wait a few seconds which appears to work but that is not feasible as this service will see a lot of action during peak times. I am not sure if the DFS is taking too long to show the file as existing or if I am facing some sort of cache issue. Any and all suggestions are greatly appreciated.

some of my code is below

Communicator Saving Stream
Code:
    Public Sub CopyStreamToFile(ByVal input As Stream, ByVal filename As String)
        If Not Directory.Exists(ProLibrary.ProPaths.ProPath.GetResponseSavePath()) Then
            Directory.CreateDirectory(ProLibrary.ProPaths.ProPath.GetResponseSavePath())
        End If
        Using output As New System.IO.FileStream(Path.Combine(ProLibrary.ProPaths.ProPath.GetResponseSavePath(), filename), System.IO.FileMode.Create)
            Dim data(CType(input.Length, Integer)) As Byte
            input.Read(data, 0, CType(input.Length, Integer))
            output.Write(data, 0, CType(input.Length, Integer))
            output.Flush()
        End Using
        msRespSaveFile = Path.Combine(ProLibrary.ProPaths.ProPath.GetResponseSavePath(), filename)
    End Sub

Provider accessing file after return
Code:
            FileInfo fInfo = new FileInfo(zipfilename);
            FileInfo fXMLInfo = null;
            //WaitForFileExists(zipfilename);
            fInfo.Refresh();
            if (fInfo.Exists)


Code I am using to make provider wait (it is ugly! :))
Code:
        Public Sub WaitForFileExists(string zipfilename)
            for (int i = 0; i < 20; i++)
                if (!File.Exists(zipfilename))
                    ProLibrary.Utility.UtilityClass.ODS(String.Format("Loop Zip File Does Not Exist: {0:s}", zipfilename))
                    Thread.Sleep(250);
                end if
            next
        end sub
 
First, the last two bits of code are some mix of c++ and vb so as they sit they couldn't work at all. Were you originally doing this in c++ or picked it up from some code and you need help converting it, still doing it in c++, or what?

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top