File IO error

J

John

Hi all:

I have a web application that plugs into to allow users to read local files
and then upload those files to Sharepoint, but for some reason when I try to
run the code from a client machine (it works fine on the server) I get the
following exception:

System.IO.IOException: The device is not ready.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize,
FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean
bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access)
at WebService1.WebForm1.uploadDocToSts() in
c:\Inetpub\Development\stsupload\upload.aspx.cs:line 141

Here is the code:

try
{
// Grab the local file and read it into the buffer
FileStream fStream = new FileStream(sFileName, FileMode.Open,
FileAccess.Read);
byte[] byteBuffer = new byte[fStream.Length];
fStream.Read(byteBuffer, 0, Convert.ToInt32(fStream.Length));
fStream.Close();

}
catch (Exception F)
{
txtDebug.Text += "File Error " + F.ToString();
}
Can anyone make a suggestion?

John.
 
J

Jeff Dillon

What do you mean "on the client". What you posted is server code. sFileName
better be a file on the server
 
J

John Saunders

John said:
Hi all:

I have a web application that plugs into to allow users to read local
files and then upload those files to Sharepoint, but for some reason when
I try to run the code from a client machine (it works fine on the server)
I get the following exception:

System.IO.IOException: The device is not ready.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32
bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String
msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access)
at WebService1.WebForm1.uploadDocToSts() in
c:\Inetpub\Development\stsupload\upload.aspx.cs:line 141

Here's how to fix this. Assume that your computer isn't lying.

If that's true, then there's a real device that's really not ready.

Which device could it be?

try
{
FileStream s = new FileStream(sFileName, ...);
}
catch (Exception ex)
{
throw new Exception(string.Format("Can't deal with file {0}",
sFileName), ex);
}


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top