C# 使用用户上传的文件解析URL
正在尝试分析发送到此web表单中的文件夹的上载URL。表单最初只允许1次上传,但现在他们希望添加更多内容,我不知道如何解析URL,用户可以上传任意数量的表单,我已经包括了我现在的代码C# 使用用户上传的文件解析URL,c#,asp.net,webforms,C#,Asp.net,Webforms,正在尝试分析发送到此web表单中的文件夹的上载URL。表单最初只允许1次上传,但现在他们希望添加更多内容,我不知道如何解析URL,用户可以上传任意数量的表单,我已经包括了我现在的代码 protected void UploadButton_Click(object sender, EventArgs e) { if (fuSample.HasFile) { foreach (HttpPostedFil
protected void UploadButton_Click(object sender, EventArgs e)
{
if (fuSample.HasFile)
{
foreach (HttpPostedFile UploadButton in fuSample.PostedFiles)
try
{
string filename = Path.GetFileName(fuSample.FileName);
fuSample.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["FileUploadFolder"]) + filename);
fileMessage.Text += String.Format("{0} <br />", UploadButton.FileName);
presentation.UploadPath += Server.MapPath(ConfigurationManager.AppSettings["FileUploadFolder"]) + filename;
UploadPathTextBox.Text = presentation.UploadPath;
}
catch (Exception ex)
{
fileMessage.Text = "Upload Status: The file(s) could not be uploaded. The following error occured: " + ex.Message;
}
protectedvoiduploadbutton\u单击(对象发送方,事件参数e)
{
if(fuSample.HasFile)
{
foreach(fuSample.PostedFiles中的HttpPostedFile上载按钮)
尝试
{
字符串文件名=Path.GetFileName(fuSample.filename);
fuSample.SaveAs(Server.MapPath(ConfigurationManager.AppSettings[“FileUploadFolder”])+文件名);
fileMessage.Text+=String.Format(“{0}
”,UploadButton.FileName);
presentation.UploadPath+=Server.MapPath(ConfigurationManager.AppSettings[“FileUploadFolder”])+文件名;
UploadPathTextBox.Text=presentation.UploadPath;
}
捕获(例外情况除外)
{
fileMessage.Text=“上载状态:无法上载文件。出现以下错误:“+ex.Message;
}
这有帮助吗?看起来您应该只使用UploadButton.FileName
来获取每个HttpPostedFile的文件名
——在循环每个PostedFile时使用UploadButton变量名似乎有点奇怪,因为这是按钮单击事件的ID。