Click here to Skip to main content
15,885,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if you want upload files in different directories.
sample code: I have 17 file upload controls for 17 different documents.

System.Web.UI.WebControls.FileUpload inputFile; 
inputFile = this.FileUpload; 
if ((!(inputFile.PostedFile == null) && (inputFile.PostedFile.ContentLength > 0))) 
{ 
    // Get the name of the file to be uploaded and 
    // the location where the file needs to be saved. 
    string extension = Path.GetExtension(inputFile.PostedFile.FileName); 
    string saveLocation = (this.Page.Server.MapPath("..\\Data\\" + BUSINESSNAME.Text + "\\")); 
    { 
        try 
        { 
            // Save the file. 
            inputFile.PostedFile.SaveAs(saveLocation + "CSB" + BUSINESSNAME.Text + extension); 
            this.Page.Response.Write("The file has been uploaded."); 
        } 
        catch (Exception ex) 
        { 
            this.Page.Response.Write(("Error: " + ex.Message)); 
        } 
        this.Page.Response.Write(" file upload."); 
    } 
} 


so it uploads and changes the file name to CSB + whatever the name of the business name in the text box and with whatever existing extension. I have this code 17 times I believe there has to be a better way.

On my file upload. The user has 11 certification documents to upload, four business history documents, a resident experience and a commercial experience document.

So where "CSB" I substituted what certificate and whatever document name would be for that business.
Posted
Updated 7-Apr-11 7:32am
v3

1 solution

Instead of having the same code again and again, you can have a web user control with this business logic encapsulated. So you just need to add the web user control multiple times, but not the coding.

Is that work for you?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900