none
Exception Problem in C# RRS feed

  • Question

  • Hello everyone, im using VS2005, i have a webpage in which i have a FileUpload control, and a Submit button. On the Submit button (.cs)page, i call this line :

    FileStream FilStr = new FileStream(FileUpload1.FileName, FileMode.Open);
    BinaryReader BinRed = new BinaryReader(FilStr);

    but at run time whenever i select a file and then click on submit button, it gives me the following exception at the above line of code:

    System.IO.FileNotFoundException: Could not find file 'C:\WINDOWS\system32\test_logo.PNG'. File name: 'C:\WINDOWS\system32\test_logo.PNG' 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) at Reports_DynamicImage.btnSubmit_Click(Object sender, EventArgs e) in d:\Projects

     

    plz tell me whats wrong with this, and y its looking the image in the C:\\windows as the image is in the Mypictures foders of the My Documents. I includede the using System.IO namespace also but this exception still comes. help me its urgent
    reply me asap.


    Thanx in Advance.

    Tuesday, June 12, 2007 11:09 AM

All replies

  • The FileName just gives the name of the file. Not a complete path

     

    If you want to open a stream to the file you could use the FileContent property. The code for the SubmitButton eventhandler looks like this: 

     

    Stream stream = FileUpload1.FileContent;

    BinaryReader reader = new BinaryReader(stream);

     

    If you want to upload a file you could use the SaveAs method:

     

    string completePath = Path.Combine("c:\\MyUploads",FileUpload1.FileName);

    FileUpload1.SaveAs(completePath);

    Tuesday, June 12, 2007 12:02 PM