Friday, October 22, 2010

Plusieurs fichiers Télécharger comme Gmail

à l'aide de System.Web.
à l'aide de System.Web.Security ;
à l'aide de System.Web.UI ;
à l'aide de System.Web.UI.HtmlControls ;
à l'aide de System.Web.UI.WebControls.
à l'aide de System.Web.UI.WebControls.WebParts.
à l'aide de System.IO.
à l'aide de System.Text ;
espace de noms MultipleFileUpload
{
la classe partielle publique MultiFileCntrl : System.Web.UI.UserControl
{
# Region variables globales
HttpFileCollection objFileCollection.

# endregion
# Region Page_Load
protégé void Page_Load (object sender, EventArgs e)
{
Si (! IsPostBack)
{
AddControl() ;
}
}
# endregion
# Region AddControl
protégé void AddControl (objet sender, e CommandEventArgs)
{
int intCount = Convert.ToInt32(txtCount.Text) ;
String [] strPath = nouvelle chaîne [intCount].
FileUpload myFileUpload = nouvelle FileUpload() ;
myFileUpload.ID = « myFileUpload » + Convert.ToString(intCount).
phUpadatePanel.Controls.Add(myFileUpload) ;
Littéral objLiteral = nouvelle Literal() ;
objLiteral.Text = « supprimer ».
phUpadatePanel.Controls.Add(objLiteral) ;
updPnlFreshContentHolder.Update() ;
}
# endregion
# Region AddControl()
protégé void AddControl()
{
int intCount = Convert.ToInt32(txtCount.Text) ;
String [] strPath = nouvelle chaîne [intCount].
FileUpload myFileUpload = nouvelle FileUpload() ;
myFileUpload.ID = « myFileUpload » + Convert.ToString(intCount).
this.phUpadatePanel.Controls.Add(myFileUpload) ;
Littéral objLiteral = nouvelle Literal() ;
objLiteral.Text = « supprimer ».
phUpadatePanel.Controls.Add(objLiteral) ;
}
# endregion
# Region UploadFiles
public UploadFiles void (object sender, EventArgs e)
{
objFileCollection = Request.files ;
Start_DocumentUpload() ;
txtCount.Text = « 0 ».
AddControl() ;
}
# endregion
# Region méthode de téléchargement de fichiers Start_DocumentUpload()
public Start_DocumentUpload() void
{
chaîne strPath = Path.GetTempPath() ;
chaîne strFileName = String.Empty ;
StringBuilder strBuilder = nouvelle StringBuilder() ;
chaîne documentDestinationPath = String.Empty ;
chaîne documentIds = String.Empty ;
chaîne documentPhysicalName = String.Empty ;
BOOL blnError = false ;
pour (int I = 0; je< objfilecollection.count;="">
{
HttpPostedFile postedFile = objFileCollection [i].
Si (postedFile.FileName! = String.Empty)
{
Essayez
{
documentDestinationPath = Path.GetTempPath() ;
chaîne FileName = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('\\') + 1).
documentDestinationPath += FileName.
Si (File.Exists(documentDestinationPath))
File.Delete(documentDestinationPath) ;
postedFile.SaveAs(documentDestinationPath) ;
}
catch (exception ex)
{
blnError = true ;

Une erreur est survenue pendant le téléchargement de fichiers: "+ postedFile.FileName +"

}
}
}
Si (blnError)
{
Page.RegisterStartupScript ("erreur", @ « »).
}
}
# Region, un message d'erreur
chaîne publique Error_Message()
{

}
# endregion
# endregion
}
}

No comments:

Post a Comment