ranjit9

ranjit9

  • NA
  • 4
  • 0

Uploading files using HtmlInputFile and FileStream

Apr 21 2004 8:57 PM
Hi, I am trying to upload files using HtmlInputFile control and FileStream object, When I run this APSX page in the localhost, I was able to upload files , but when I do from a different machine, I get the following error. Error************* System.IO.FileNotFoundException: Could not find file "C:\COMLOG.txt". File name: "C:\COMLOG.txt" at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at NPRReport.AddReport.ReadFileToBuffer(String fileName) End Error************* I checked the permissions on the file being uploaded, it has everyone full permissions. And here is the code I am doing it. Code***********snippet******** private byte[] ReadFileToBuffer(string fileName) { /* * Accepts HtmlInputFile control. returns a byte array */ byte[] buffer=new byte[0]; try { //Instance a new FileStram obj to read into.(You might have File Permission error when reading the file) lblError.Text=fileName; FileStream stream = new FileStream(fileName, FileMode.Open,FileAccess.Read); // Create a buffer to hold the stream bytes buffer = new byte[stream.Length]; // Read the bytes from this stream stream.Read(buffer, 0, (int)stream.Length); //close the stream stream.Close(); } catch(Exception ex) { throw new Exception(ex.Message + "Error Stack : " + ex.StackTrace + "Additional Info ; " + ex.GetBaseException()); } return buffer; } End Code snippet*************** Can anyone provide some insight here please? Thank you very much in advance for you help and suggestions. Ranjit