我正在寻找一种更好的方式来进行多文件上传. [英] I am looking for a better way to do Multiple file upload.
问题描述
如果要在其他目录中上传文件.
示例代码:我有17个文件上传控件,可用于17个不同的文档.
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.");
}
}
因此它会上传文件名并将其更改为CSB +文本框中的商户名称名称,并带有现有扩展名.我有17次此代码,我相信必须有更好的方法.
在我的文件上载.用户有11个要上传的认证文档,四个业务历史文档,一个居民体验和一个商业体验文档.
因此,在"CSB"处,我替换了该业务的证书和文件名.
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.
推荐答案
您可以一次又一次地使用相同的代码,而不用使用相同的代码封装了此业务逻辑的Web用户控件.因此,您只需要多次添加Web用户控件,而无需添加代码.
那对你有用吗?
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?
这篇关于我正在寻找一种更好的方式来进行多文件上传.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!