FileUpload 控件上传图片和文件

2012年1月19日

 

//获取文件名称

string fileName=FileUpload1.FileName;

//获取文件的大小

string fileSize=FileUpload1.PostedFile.ContentLength.ToString();

//获取文件的类型

string flieType=FileUpload1.PostedFile.ContentType;

//获取文件的后缀名

string fileNameType=fileName.Substring(fileName.LastIndexOf("."+1);

//是图片的保存路径;img为服务器目录上的文件夹

string ImgSavePath=Server.MapPath(Request.ApplicationPath+"/img")+"\\"+fileName;

//是文件的保存路径;file为服务器上目录上的文件夹

string FileSavePath=Server.MapPath(Request.applicationPath+"/file")+"\\"+fileName;

//在项目上的路径

string projectPath=Request.ApplicationPath+"img/"+fileName;

if(fileNameType=="jpg"||fileNameType=="bmp"||fileNameType=="gif"){

     FileUpload1.SaveAs(ImgSavePath);

     Image1.ImageUri=projectPth;

}

else

{

   FileUpload1.SaveAs(FileSavePath);

   Image.Visible=false;

}

posted @ 2012-01-19 17:24  kingjust  阅读(887)  评论(0编辑  收藏  举报