|
با استفاده از این کد شما می توانید فایل مورد نظر خود را مستقیم بر روی سرور بارگزاری نمایید . این کد به زبان VB.NET است . در صورتی که در هنگام بارگزاری فایل با مشکل مواجه شدید به تنظیمات سرور و مجوز ارسال فایل بر روی دایرکتوری مورد نظر مراجعه نمایید. این برنامه فایل را در دایرکتوری File بارگزاری می نماید.
<%@ CodePage=65001 %> <script language="VB" runat="server"> Sub Page_Load(S As Object, E As EventArgs)
end sub
Sub Upload(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs)
If Not (myFile.PostedFile Is Nothing) Then
Dim intFileNameLength as Integer Dim strFileNamePath as String Dim strFileNameOnly as String
strFileNamePath = MyFile.PostedFile.FileName intFileNameLength = Instr(1, StrReverse(strFileNamePath), "\") strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath)-intFileNameLength)+2) dim strPath strPath = Request.ServerVariables("PATH_INFO") strPath =Trim(Mid(strPath,1,InStrRev(strPath,"/")) & "") myFile.PostedFile.SaveAs(Server.MapPath(strPath) & "\file\" & strFileNameOnly)
End If End Sub </script> <html dir="rtl">

<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Upload file</title> </head>
<body topmargin="0" bottommargin="0" rightmargin="0" leftmargin="0">
<table border="0" dir="rtl" width="100%"><tr><td valign="top"> <table border="0" width="100%"><tr><td> <form runat="server"> <table border="0" width="100%" align="center" ><tr> <td align="center"> <a href="http://www.novinweb.com" target="_blank"> <img border="0" src="file/novinweb.jpg" width="170" height="60"></a></td></tr></table> <table border="0" width="100%" align="center" bgcolor="#CCE6FF"><tr> <td align="center"><span lang="fa"><font face="Tahoma">ارسال فایل</font></span></td></tr></table>
<table border="0" width="100%" dir="ltr" bgcolor="#FFF4DF"><tr><td dir="rtl" align="right"> <input id="myFile" type="file" runat="server" size="54"> <asp:Button ID="btup" Text="Upload" Font-Name="tahoma" Font-Size="8" OnCommand="Upload" Runat="server" /></td> <td><p align="right"><font face="Tahoma" size="1">بارگذاري فایل</font></td></tr></table> </form> </td></tr></table> </td></tr></table>
</body> </html>
کلمات کلیدی: طراحی سایت , نمونه کد , کد بارگذاری فایل , آپلود , آموزش طراحی وب دات نت
Keyword: Upload Source code, Web design , ASP.net
|