2013-04-25 23 views
0

我上傳文件使用asp.net fileupload控制,每當回發發生由於頁面上的其他字段,文件上傳控制丟失選定的路徑。我在頁面上使用多個文件上傳控件來進行比較。目的如何解決這個問題?親愛的合適的例子請幫助簡單&。如何解決回發問題文件上傳控制的路徑不存在

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); 
} 
+0

你能指定這些代碼的位置嗎? – lexeRoy 2013-04-25 06:22:09

回答

0

雖然上上傳按鈕,點擊... 你的頁面重定向到第一Page_Load事件,在其中設置頁值。 對於在

page_load(..) 
{ 
    if(!IsPostBack) 
    { 
     ..setpagevalues(); 
    } 
} 

這主要振振有辭...你得到空路徑.... 試試吧..

0

如果您使用的是帶有更新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" /> 

你可以看到,當你點擊其他動作按鈕時,文件上傳將會有值。

將更新後控件放在更新面板中,並使文件上傳控件出現在更新面板的 中。

0

您只需使用文件上傳與的UpdatePanel,也把ViewStateMode =「啓用」到文件上傳。

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
      <ContentTemplate> 
<asp:FileUpload ID="FileUpload1" runat="server" ViewStateMode="Enabled"/> 
</ContentTemplate> 
     </asp:UpdatePanel> 
相關問題