Steve Lydford on .Net

Sticking all my useful bits in one place in the hope that I may find them again one day!
posts - 4, comments - 0, trackbacks - 0

My Links

News

Hi. This just a collection of useful bits and pieces that I am posting here so that I might be able to find them again in the future. Feel free to browse through and use anything that may be of some help to you.

Archives

Post Categories

Uploading Files in ASP.Net

Just a quickie to show how to use the FileUpload control in ASP.Net.

The following is the click event of a button called btnUpload. The only catch-me-out is that you need to make sure that sufficient rights have been granted to the folder which you want to upload the files to, for the ASP.Net user.

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
        string SaveLocation = Server.MapPath("d:\\Data\\Uploads") + "\\" + fn;
        try
        {
            FileUpload1.PostedFile.SaveAs(SaveLocation);
        }
        catch (Exception ex)
        {
            Response.Write("Error: " + ex.Message);
 
        }
    }

Print | posted on Wednesday, May 14, 2008 12:13 PM | Filed Under [ C# ASP.Net ]


Feedback

No comments posted yet.


Post Comment

Title  
Name  
Email
Url
Comment   
Please add 2 and 7 and type the answer here:

Powered by: