Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

FileUpload1 Visual c#/ASP

  • 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, Registered Users 2 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