Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

FileUpload1 Visual c#/ASP

Options
  • 22-03-2007 12:28am
    #1
    Closed Accounts Posts: 68 ✭✭


    Hi,
    When using FileUpload1 control creating an ASP web page, it only seems to be returning the file name, not the full directory + file name.
    string FileToUpload = FileUpload1.FileName;
    

    ^^ FileToUpload becomes "filename.ext" instead of "c:\directory\filename.ext"
    Also have tried using path:
    string path = Path.GetDirectoryName(FileUpload1.FileName);
    

    Help?


Comments

  • Registered Users Posts: 640 ✭✭✭Kernel32


    That is the way it is supposed to work. What relevance does a client side directory path even have on the server? The fact that you are doing a Path.GetDirectoryName(FileUpload1.FileName) seems to indicate you don't really understand how file uploads work. The file is streamed from client the server along with it's original name. There is no path information, and if there was it wouldn't be of any use.


  • Closed Accounts Posts: 68 ✭✭nupplenits


    Kernel32 wrote:
    That is the way it is supposed to work. What relevance does a client side directory path even have on the server? The fact that you are doing a Path.GetDirectoryName(FileUpload1.FileName) seems to indicate you don't really understand how file uploads work. The file is streamed from client the server along with it's original name. There is no path information, and if there was it wouldn't be of any use.


    Well Path.GetDirectoryName... was only a last resort since FileUpload1.FileName was not returning the full directory.
    How can a file be uploaded if the program only knows the name of the file and not the directory where it is stored?

    Here is my code.
    String FileToUpload = FileUpload1.FileName;
            UploadFile(FileToUpload);
    
    private void UploadFile(string filename)
            {
    
    
                FileInfo fileInf = new FileInfo(filename);
    
                .........
                .........
                FtpWebRequest reqFTP;
                .......
    
    
    
    // Notify the server about the size of the uploaded file
    
                reqFTP.ContentLength = fileInf.Length;
    
    ^^^^^This is where I get the below error..


    Error:
    System.IO.FileNotFoundException was unhandled by user code
    Message="Could not find file 'LICENSE'."


    If I manually type the file(including dir) into a textbox and do:
    string FileToUpload = txtUploadFile.Text;
    UploadFile(FileToUpload);
    

    it works perfectly.


Advertisement