Torna al Thread
public void UploadMultipleFiles(Object Sender,EventArgs e )
{
//Variable to hold the result
string m_strResultMessage = "";
//Variable to hold the FileName
string m_strFileName;
// 'Variable FolderName where the files will be saved
string m_strFolderName =Server.MapPath("./Report_file/");// @"C:\TempMultipleFiles\";
//'Variable to hold the File
HttpPostedFile m_objFile;
//Response.Write(this.MHL3000.Value);
//'Variable used in the Loop
int i ;
ResultMsg.Visible = false;
try
{
// 'Loop Through the Files
for (i = 0;i < Request.Files.Count ;i++)
{
//Get the HttpPostedFile
m_objFile = Request.Files[i];
//Check that the File exists has a name and is not empty
if (!((m_objFile.FileName == "") || (m_objFile.ContentLength < 1)))
{
//Get the name of the file
m_strFileName = m_objFile.FileName;
m_strFileName = Path.GetFileName(m_strFileName);
//Creates the folder if it does not exists
if (!Directory.Exists(m_strFolderName))
{
Directory.CreateDirectory(m_strFolderName);
}
//Save each uploaded file
m_objFile.SaveAs(m_strFolderName + m_strFileName);
//Assign the File Name and File Type to Result
m_strResultMessage = m_strResultMessage + "Uploaded File: " + m_objFile.FileName + " of type " + m_objFile.ContentType + " <br> ";
//Hide the Multiple Form Upload Panel
//MultipleFileUploadForm.Visible = false;
}
}
//If no files where selected provide a user friendly message
if (m_strResultMessage == "")
{
//Unhide the Result Label
ResultMsg.Visible = true;
m_strResultMessage = "Select atleast one file to upload.";
this.ResultMsg.Text = m_strResultMessage;
}
//}
}
catch (Exception errorVariable)
{
//Trap the exception
m_strResultMessage = errorVariable.ToString();
Response.Write( m_strResultMessage + "<br><br><br><br>" );
}
//Assign the Result to ResultMsg Label Text
DirectoryInfo infofile = new DirectoryInfo(Server.MapPath("./Report_file/"));
this.Dginfo.DataSource = infofile.GetFiles("*.*");
this.Dginfo.DataBind();
}