File IO error

Discussion in 'ASP .Net Web Services' started by John, Nov 2, 2006.

  1. John

    John Guest

    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.
     
    John, Nov 2, 2006
    #1
    1. Advertising

  2. John

    Jeff Dillon Guest

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


    "John" <> wrote in message
    news:...
    > 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.
    >
    >
     
    Jeff Dillon, Nov 2, 2006
    #2
    1. Advertising

  3. "John" <> wrote in message
    news:...
    > 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
     
    John Saunders, Nov 3, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hfk0
    Replies:
    2
    Views:
    21,683
  2. JavaQueries
    Replies:
    1
    Views:
    3,687
    John C. Bollinger
    Mar 1, 2005
  3. Balaji
    Replies:
    3
    Views:
    10,122
  4. Bishop
    Replies:
    1
    Views:
    797
    Bishop
    Feb 24, 2007
  5. juvi
    Replies:
    3
    Views:
    1,055
    Alexey Smirnov
    Jan 22, 2009
Loading...

Share This Page