• 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;

    }

  • 相关阅读:
    跨域问题注解解决
    跳出循环到指定位置
    idea model管理
    maven 取本地jar
    注解 元注解
    手动打jar包到maven
    sonar搭建
    jmockit、junit
    注解
    虚拟机指令
  • 原文地址:https://www.cnblogs.com/wggWeb/p/2327531.html
Copyright © 2020-2023  润新知