使用c#在asp.net上传文本文件a [英] Upload Textfile a in asp.net using c#
本文介绍了使用c#在asp.net上传文本文件a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请告诉我如何使用Fileupload控制按钮在Asp.net上传文本文件。
解决方案
从客户端上传文件:
ASPX:
< 输入 id = inFilename 类型 = 文件 runat = server size = 65 / >
< br / >
< asp:按钮 ID = butUpload 文字 = 恢复 OnClick = butUpload_Click
< span class =code-attribute> runat = server > < / asp:按钮 >
生成输入字段浏览按钮,以便用户可以选择文件源。 Size参数是WHOLE控件应占用的可用空间的百分比。
APSX.cs:
public void butUpload_Click( object sender, System.EventArgs e)
{
Stream inStream = inFilename.PostedFile.InputStream;
int length = inFilename.PostedFile.ContentLength;
string contentType = inFilename.PostedFile.ContentType;
byte [] binaryData = new byte < /跨度> [长度];
int n = inStream.Read(binaryData, 0 ,length);
}
您好,
查看此
受保护 void Button1_Click( object sender,EventArgs e)
{
if (FileUpload1.HasFile)
{
string Savepath = Server.MapPath( 〜/ Uploaded / + FileUpload1.FileName);
FileUpload1.SaveAs(Savepath);
}
}
< div >
< asp:按钮 ID = Button1 runat = server 文本 = 按钮 onclick = Button1_Click / > < asp:FileUpload ID = FileUpload1
runat = server / >
< span class =code-keyword>< / div > ;
最好的问候
M.Mitwalli
< blockquote>上传图片或文本文件没有区别。
以下供参考:
文件上传控件 [ ^ ]
使用ASP.NET上传文件 [ ^ ]
试用!
Hi,
Please let me how to upload a Textfile in Asp.net using a Fileupload control button.
解决方案
Upload file from client:
ASPX:
<input id="inFilename" type="file" runat="server" size="65" /> <br /> <asp:Button ID="butUpload" Text="Restore" OnClick="butUpload_Click" runat="server"></asp:Button>
Generates the input field with "Browse" button so the user can select the file source. The Size parameter is the percentage of available space the WHOLE control should occupy.
APSX.cs:
public void butUpload_Click(object sender, System.EventArgs e) { Stream inStream = inFilename.PostedFile.InputStream; int length = inFilename.PostedFile.ContentLength; string contentType = inFilename.PostedFile.ContentType; byte[] binaryData = new byte[length]; int n = inStream.Read(binaryData, 0, length); }
Hi ,
Check this
protected void Button1_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { string Savepath = Server.MapPath("~/Uploaded/" + FileUpload1.FileName); FileUpload1.SaveAs(Savepath); } }
<div> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><asp:FileUpload ID="FileUpload1" runat="server" /> </div>
Best Regards
M.Mitwalli
There is no difference in uploading an image or a textfile.
Following for reference:
FileUpload control[^]
File Upload with ASP.NET[^]
Try out!
这篇关于使用c#在asp.net上传文本文件a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文