文件上传 文件路径

来源:互联网 发布:esports海涛淘宝店 编辑:程序博客网 时间:2024/05/01 22:45
string basePath=AppDomain.CurrentDomain.BaseDirectory;//绝对路径
string basePath=Request.ApplicationPath;//相对路径
string strPath = Server.MapPath("~/upload");
文件上传大小的限制:用File   Field组件选择文件上传,文件大小不能超过4M,超过4M,提示出错,有没有办法上传超过4M的文件?
在web.config文件的   <configuration>   </configuration>  
  中添加<httpRuntime   executionTimeout="90"   maxRequestLength="100000"   useFullyQualifiedRedirectUrl="false"   />
需要在web.config或machine.config的<system.web>部分中修改<httpRuntime>元素的maxRequestLength值。因为其默认值为4096byte,所以你只能上传小于4M的文件:)

The ' ' character, hexadecimal value 0xA0, cannot begin with a name.
这个错误是由于config文件中使用了连续的两个空格。此外,代码0xA0定义为一个非断开的空格(这意味着在编排格式时,该字符不用于断开一行),代码0xAD是一个软连字符(表示...character set)。

opener.top.InsertText('<img src=images/"<A>'">+filename+@">'</A>);
插入图片的js脚本
System.Web.HttpFileCollection attachments = System.Web.HttpContext.Current.Request.Files;
这是文件上传的一种写法格式
string Dir = Request.PhysicalApplicationPath + @"upload/workinstance/";
获得物理地址,绝对路径
for(int i=0;i<Request.Files.Count;i++)
{
                        if(Request.Files[i].FileName.Trim().Length >0)
{
                            HttpPostedFile file = Request.Files[i];
if( file!=null && file.FileName.Length>0 )
{                                string extension=Path.GetExtension(file.FileName);                if(!(extension==".htm"||extension==".html"||extension==".mht"))        {
                            string str="扩展名为"+extension+"是不允许的文件类型,文件类型只允许为htm、html或mht类型!";
                                Response.Write("<script>window.alert('"+str+"');</script>");
                                return;
                                }
num++;
}
}
}   
if(num==0)
{
Response.Write("<script>window.alert('没有文件上传,添加失败!');</script>");
}