易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET文件上传,为每个用户建立一个上传目录

文件上传界面既可以用Html的input file控件,又可以用FileUpload控件,只要将Html的input file控件加上runat="server",就会发现两者的功能完全是一模一样,上传的代码是共用的,不需要做任何改变。我想微软在将Html控件将成标准控件时应该只是多加了runat="server"吧。放入上述两者的任一控件后,添加一个标准的Button按钮(Html按钮也行,不过需要加上runat="server"),双击Button按钮,产生点击事件。在点击事件中写入以下代码:
首先检查是否已经选了文件
if (this.myFile.PostedFile != null)
{
检查文件根目录是否存在,不存在就要创建
if (!System.IO.Directory.Exists(Server.MapPath("~")+@"\photoes"))
{
      System.IO.Directory.CreateDirectory(Server.MapPath("~")+@"\photoes");
}
此处Server.MapPath("~")用来表示项目根目录的物理路径。
接下来创建用户文件夹,根据用户ID创建
if(!System.IO.Directory.Exists(Server.MapPath("~")+@"\photoes\"+userID))
{
     System.IO.Directory.CreateDirectory(Server.MapPath("~")+@"\photoes\"+userID)
}
string orignalName = this.myFile2.PostedFile.FileName;//获取客户机上传文件的路径
int lastdotlocation = orignalName.LastIndexOf(".");
string extendName = orignalName.Substring(lastdotlocation);//获取扩展名
 if (extendName != ".gif" && extendName != ".jpg" && extendName != ".jpeg" && extendName != ".png")
{
       Response.Write("Wrong format");
       Response.End();
}//检查文件格式
string newName = DateTime.Now.Millisecond.ToString() + "_" + myFile2.PostedFile.ContentLength.ToString() + extendName;//对文件进行重命名
myFile.PostedFile.SaveAs(Server.MapPath("~") + @"\photoes\" +userID+@"\"+ newName);
}


相关文档:

ASP.NET中cookie的几种创建和访问方法

来源:草根站长
Cookie (HttpCookie的实例)提供了一种在 Web 应用程序中存储用户特定信息的方法。例如,当用户访问您的站点时,您可以使用Cookie 存储用户首选项或其他信息。当该用户再次访问您的网站时,应用程序便可以检索以前存储的信息。
ASP.NET中的cookie:创建Cookie方法 (1)
Response.Cookies["userName"].Valu ......

ASP.NET 生命周期

ASP.NET 生命周期
对于Asp.net页面层开发无论是写页面还是写控件,我觉得都可以用一句话描述:"Do the right thing at the right time in the right place."
本文通过记录页面事件的触发顺序看请求的处理流程,从中可以看出ASP.NET 的生命周期
创建一个网站,在页面上添加一个Label和一个Button,在Default.aspx.cs中修改 ......

浅析ASP.NET生成随机密码(转)

 实现ASP.NET生成随机密码功能是很容易的,下面的代码给出了完整的实现方法:
public static string MakePassWord(string PwdChars, int Pwdlen)
{
    string mpstr = "";
    int iRandNum;
    Random mrnd = new Random();
    for (int ......

Asp.Net Master模板页的控件和属性

 内容页访问MasterPage中的控件,有两种解决方案:
一、是用弱类型访问
    使用 FindControl 方法获取模板页的控件
    ((Label)Master.FindControl("Label1")).Text = "xxx";
  
二、给模板页添加属性来使用强类型访问(推荐)
    模板页定义;
&nb ......

asp.net 运行原理

主要类:
  System.Web.HttpRuntime
  System.Web.HttpApplicationFactory
  System.Web.HttpApplication
  System.Web.Compilation.BuildManager
  System.Web.Compilation.ApplicationBuildProvider
  System.Web.Compilation.BuildProvidersCompiler
  System.Web.UI.PageHandlerFactory
请求处理 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号