Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Issue in Uploading files using FileInfo

Issue in Uploading files using FileInfo

Scheduled Pinned Locked Moved ASP.NET
visual-studiohelpcsharpsysadminhosting
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saini arun
    wrote on last edited by
    #1

    Hello, I am trying to upload files using CopyTo function of FileInfo. The code I am using is as follows...

    FileInfo fileObj = new FileInfo(filUpload1.PostedFile.FileName);
    string fileType = filUpload1.PostedFile.ContentType;
    string newFileName = "test.txt";

    string folderPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads");

    fileObj.CopyTo(folderPath + "\\" + newFileName);

    The exception I am getting is... Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\help.txt'. Help.txt is the name of the file I selected using FileUpload control. I could have used the SaveAs function of FileUpload control but I want to try it using above method. The files gets successfully uploaded when I do it on my machine but after uploading it on web server, it throws the above exception. Please suggest. Thank You.

    M 1 Reply Last reply
    0
    • S saini arun

      Hello, I am trying to upload files using CopyTo function of FileInfo. The code I am using is as follows...

      FileInfo fileObj = new FileInfo(filUpload1.PostedFile.FileName);
      string fileType = filUpload1.PostedFile.ContentType;
      string newFileName = "test.txt";

      string folderPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads");

      fileObj.CopyTo(folderPath + "\\" + newFileName);

      The exception I am getting is... Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\help.txt'. Help.txt is the name of the file I selected using FileUpload control. I could have used the SaveAs function of FileUpload control but I want to try it using above method. The files gets successfully uploaded when I do it on my machine but after uploading it on web server, it throws the above exception. Please suggest. Thank You.

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      Well Mr. Lucknow, The reason behind this exception is that it is trying to find the file to be copied (in your case, it is help.txt) on the web server where it is not present. In short, you can use this way to upload file to the web server. :rose:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups