ASP.NET MVC Uploading and Downloading Files
If you come to ASP.NET MVC from a purely ASP.NET Web Forms background, one of the first things you are likely to notice is that all those nice easy Server Controls have disappeared. One of those is the FileUpload, and its absence seems to cause a few problems. This article looks at how to upload files to the server in an MVC world, and how to get them back from the server to the user again.
In Web Forms, when you drag a FileUpload control on to the designer, something happens when the page is rendered which you probably don't notice. The resulting html form that wraps the entire page is decorated with an extra attribute: enctype="multipart/form-data". The FileUpload itself is rendered as an html input type=file. Within an MVC View, there are a number of ways to set this up. The first is with HTML:
<form action="/" method="post" enctype="multipart/form-data">
<input type="file" name="FileUpload1" /><br />
<input type="submit" name="Submit" id="Submit" value="Upload" />
</form>
Notice that the <form> tag includes the enctype attribute, and method attribute of post. This is needed because the form by default will be submitted via the HTTP get method. The following approach, using the Html.BeginForm() extension method renders the exact same html when the page is requested:
<%
using (Html.BeginForm("", "home", FormMethod.Post, new {enctype="multipart/form-data"}))
{%>
<input type="file" name="FileUpload1" /><br />
<input type="submit" name="Submit" id="Submit" value="Upload" />
<% }%>
Notice the name attribute of the <input type="file"> element. We'll come back to that shortly. In the meantime, the resulting page should look rather blandly like this:
OK. So we can now browse to a local file and click the submit button to upload it to the web server. What is needed next is some way to manage the file on the server. W
相关文档:
using System.Web.Mail ;
private void Button1_Click(object sender, System.EventArgs e)
{
//实例化MailMessage对象
System.Web.Mail.MailMessage mail=new System.Web.Mail.MailMessage();
//定义邮件的发送地址 , 可以随便填一个不存在的地址 ......
在最近的项目中,遇到一个问题,要实现这样的效果:
点pic_small.Aspx页面的缩略图后弹出pic_all.aspx页面,pic_all.aspx页面的大小要根据图片大小自动调整,而且要有图片的说明信息,还可以点上一幅和下一幅等进行翻页。
实现过程如下:
pic_small.Aspx页面缩略图处的代码为:
<IMG id="imgPic" style="CURSOR: h ......
前台 如果你用的是 gridview 就把Repeater替换成gridview 。一样的。。
<form id="frm01" action="" method="post" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
& ......
200X年12月23日的一次面试经历(共六轮),至此9-X周年之际,和各位朋友分享,希望对各位朋友有用,有些自己的答案贴出来也仅仅是抛砖引玉,希望各位朋友不吝赐教,说句老实话,面试的时候时间很紧,很难考虑最优算法。
起因是朋友推荐我去W公司应聘Senior SDE这个职位,应该算是内部推荐了,下面是招聘要求
Title: Senio ......
这几天学习使用WebPart,发现众多问题,使用点滴记录如下,同各位共享:
1、WebPart的使用必须基于一个通过身份验证的用户会话。
2、WebPart的使用的个性化应用于所有人的选项默认是禁用的,可以通过修改Web.config来完成
<webParts>
<personalization>
&nb ......