Re: [問題]請問C#寫的asp程式如何上傳至網頁?

看板C_Sharp (C#)作者 ( 小乖)時間20年前 (2005/03/03 19:29), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串3/3 (看更多)
我不太知道你想要的是什麼,不過我這有個範例從書上抄的,你看看有沒有用 <script Language="c#" runat="server"> void btnSend_click(object sender, EventArgs e) { if(txtFile.PostedFile.ContentLength == 0) { lblShow.Text="檔案傳送失敗!"; } else { lblShow.Text="檔案大小->"+txtFile.PostedFile.ContentLength+"<br>"; lblShow.Text+="檔案類型->"+txtFile.PostedFile.ContentType+"<br>"; lblShow.Text+="檔案名稱->"+txtFile.PostedFile.FileName; //取出上傳的檔案名稱 string f_name=Get_File_Name(txtFile.PostedFile.FileName); //將上傳的檔案儲存在伺服器端指定的資料夾下 txtFile.PostedFile.SaveAs(Server.MapPath(".")+"\\"+f_name); } } //Get_File_Name 函式可由完整的檔案路徑中取得檔案名稱 string Get_File_Name(string str) { string new_str=""; string file_name=""; for(int i=str.Length-1 ; i>=0 ; i--) { if(str[i].ToString() !="\\") { new_str += str[i].ToString(); } else { break; } } for(int i=new_str.Length-1 ; i>=0 ; i--) { file_name += new_str[i].ToString(); } return file_name ; } </script> <html> <head><title>檔案上傳</title></head> <body> <form enctype ="multipart/form-data" runat="server"> <p>上傳檔案路徑:<Input Type="file" id="txtFile" runat="server"><p> <p><asp:button id="btnUpload" runat="server" Text="上傳檔案" OnClick="btnSend_click"/></p> <asp:Label id="lblShow" runat="server" /> </form> </body> </html> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.73.152.26

140.119.183.211 03/03, , 1F
哈,原po只是要表達某頁不能run而己
140.119.183.211 03/03, 1F

220.134.23.117 03/04, , 2F
由此可看出,問題要別人能看懂,也是很重要的:P
220.134.23.117 03/04, 2F
文章代碼(AID): #129lK8Hf (C_Sharp)
文章代碼(AID): #129lK8Hf (C_Sharp)