Uploading document in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shaileshsharma
    New Member
    • Jun 2007
    • 26

    Uploading document in C#

    Hi,
    I am working on a web based apllication where user will upload the registration form and the form will save on a perticular server.the code which i am using is :

    string strname;
    strname = System.IO.Path. GetFileNamefile Upload.PostedFi le.FileName);



    fileUpload.Post edFile.SaveAs(S erver.MapPath(s trname));

    The problem is this when i upload the document it alwayes goes to my folder where this application is placed.(D:\\Upl oadApp) i want to change the path,is this possible.I am very much new in web application so if there is problem in concept plz. help me.

    Thanks,
    Shailesh Kumar
  • rohitkumar
    New Member
    • Aug 2007
    • 17

    #2
    Originally posted by Shaileshsharma
    Hi,
    I am working on a web based apllication where user will upload the registration form and the form will save on a perticular server.the code which i am using is :

    string strname;
    strname = System.IO.Path. GetFileNamefile Upload.PostedFi le.FileName);



    fileUpload.Post edFile.SaveAs(S erver.MapPath(s trname));

    The problem is this when i upload the document it alwayes goes to my folder where this application is placed.(D:\\Upl oadApp) i want to change the path,is this possible.I am very much new in web application so if there is problem in concept plz. help me.

    Thanks,
    Shailesh Kumar
    hi shailesh,
    try the following;
    Code:
                         string strFilePath="..c:\\foldername"+strname;
    //.. indicates the server
    //instead of c:\\foldername use the path as per your requirement
                        fileUpload.PostedFile.SaveAs(strFilePath));
    i hope this will solve the problem.
    Last edited by rohitkumar; Nov 22 '07, 07:35 AM. Reason: spelling error

    Comment

    • dotNetDummi
      New Member
      • Nov 2007
      • 9

      #3
      I apologise that I didn't start a thread but continue from this.

      I've used this method to save file into my server and it's working.
      Now I need to provide my users to download them with a button.

      May I know how to do that? The response.redire ct is not working for me.

      Code:
      protected void btnLink_OnClientClick(object sender, EventArgs e)
          {
              String pid = Convert.ToString(Session["pid"]);
              String[] file = System.IO.Directory.GetFiles((Server.MapPath("Docs/")+ pid +"/"), "myDesiredFileName.*");
             
            //  Response.Write(file[0]);
              Response.Redirect(file[0]);
              
          }
      btw, It got file name and directory correctly.

      Comment

      Working...