我正在使用asp.net文件上传控件上传文件,每当回发发生时,由于页面上的其他字段,在文件上传控件中选择的路径丢失。我在diff的页面上使用了多个文件上传控件。目的如何解决这个问题?请帮助简单和合适的例子,亲爱的。
string file = Path.GetFileName(UploadSalesServiceCopy.PostedFile.FileName);
string filepath2 = ConfigurationManager.AppSettings["ServerMapImgPath"].ToString();//.......local drive path via web config
string subPath = filepath2 + file;
bool IsExists = System.IO.Directory.Exists(Server.MapPath(subPath));
if (!IsExists)
System.IO.Directory.CreateDirectory(Server.MapPath(subPath));
if (UploadSalesServiceCopy.HasFile)
{
//UploadSalesServiceCopy.SaveAs(subPath);//PHYSICAL path
UploadSalesServiceCopy.SaveAs(Server.MapPath(subPath));//server path
}
else
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "javascript", "alert('No File Selected.')", true);
}发布于 2013-04-25 15:24:23
单击Upload按钮时...页面首先重定向到Page_load事件,您可以在其中设置页面值。为此,请参阅
page_load(..)
{
if(!IsPostBack)
{
..setpagevalues();
}
}该主reson...you正在获取空路径....试试看..
发布于 2013-04-25 17:48:43
如果你使用带有更新panel.Then的asp.net文件上传控件,问题是文件上传控件与部分回发不兼容。
<asp:FileUpload ID="fpTest1" runat="server" />
<asp:FileUpload ID="fpTest2" runat="server" />
<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnActions" runat="server" Text="Other Actions" >
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="test" runat="server" OnClick="test_Click" Text="Upload File" />您可以看到,当您单击other actions按钮时,file upload将具有这些值。
将Post back控件放入更新面板中,并将文件上载控件放在更新面板之外。
发布于 2014-03-12 15:55:05
您只需将ViewStateMode="Enabled"与一起使用,并将fileupload设置为fileupload即可。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" ViewStateMode="Enabled"/>
</ContentTemplate>
</asp:UpdatePanel>https://stackoverflow.com/questions/16207356
复制相似问题