1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Asp.net: How to upload the file into a specific folder on the sever

Discussion in 'C#' started by alanX, Aug 7, 2006.

  1. #1
    Hi all,
    I want to upload the file into a folder called "Uploadfile" rather than putting the file everywhere on the server, how to change the following code. Thanks.

     
    alanX, Aug 7, 2006 IP
  2. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    If you want to put the files within the website root then you would use server.mappath

    website root
    File1.PostedFile.SaveAs(Server.MapPath("\") + StrFileName);
    files folder
    File1.PostedFile.SaveAs(Server.MapPath("\files\") + StrFileName);

    If you want to save outside of the root then you will have to specify the full path to the location.
     
    DanInManchester, Aug 10, 2006 IP
  3. alanX

    alanX Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks,
    Now i can upload the file by following the code:
    But i have a another porblem, how to Download the "Uploadfile" with different directory. Code here only can access the "Upload file" in same directory(folder)? Plz help me
     
    alanX, Aug 14, 2006 IP
  4. DanInManchester

    DanInManchester Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    If you use the full path this should work

    e.g.

    NavigateUrl="/myfiles/somefile.pdf"
     
    DanInManchester, Aug 15, 2006 IP
  5. alanX

    alanX Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I try to use following code to access the file in different directory but on the same server. It shows "The resource cannot be found". . What probelm the code has?

     
    alanX, Aug 15, 2006 IP
  6. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #6
    this site had tons of free code snippets and examples for uploading, or ftping:

    http://www.codeproject.com/

    requires a registration to download - but is very worth it!
     
    ccoonen, Aug 17, 2006 IP
  7. cromatiq

    cromatiq Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This website has some cool free source codes on it. Thanks for posting it ccoonen. It still works.
     
    cromatiq, Oct 2, 2010 IP
  8. Deu

    Deu Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #8
    you can always get the current script root using the ~ sign and then use the Server.MapPath('your directory') will get the correct path for the server then use it to upload.
     
    Deu, Oct 6, 2010 IP