当前位置:编程学习 > C#/ASP.NET >>

system.io

C#为什么我的File命名空间中没有Exists方法呢?我已经把Using System.IO包含进去了啊 system.io --------------------编程问答-------------------- 应该没错吧
命名空間:  System.IO

 File.Exists("路径");
--------------------编程问答-------------------- file下就点不出exists不知道为什么
 为什么“报system.web.httppostedfile不包含exists” --------------------编程问答--------------------
引用 2 楼 u010891065 的回复:
file下就点不出exists不知道为什么
 为什么“报system.web.httppostedfile不包含exists”

httppostedfile类型没有exists方法啊
你用的是不是request.file啊
这个不是system.io下的file类型奥 --------------------编程问答-------------------- 我知道file是system.io下的,这个命名空间我写了但是就是不知道为什么会报那个错,请高手指点 --------------------编程问答-------------------- System.IO.File.Exists("Path");   --------------------编程问答--------------------
引用 4 楼 u010891065 的回复:
我知道file是system.io下的,这个命名空间我写了但是就是不知道为什么会报那个错,请高手指点

可以代码贴出来吗 --------------------编程问答--------------------
引用 2 楼 u010891065 的回复:
file下就点不出exists不知道为什么
 为什么“报system.web.httppostedfile不包含exists”


你用的是FileUpload.PostedFile属性,不是System.IO.File类型
那个文件是客户端上传的,
得到文件名 var file = Path.GetFileName(file.FileName);
然后加上你存储的目录 file = Path.Combine(Server.MapPath(path) + fileName);
再判断System.IO.File.Exists(file) --------------------编程问答-------------------- 自己换个变量名吧,var filePath --------------------编程问答-------------------- 要不把你的代码拿出来瞧瞧,很容易的东西搞定那复杂啊点不处理肯定就没那个方法啊, --------------------编程问答-------------------- public partial class _Default : System.Web.UI.Page 
{
     
    protected void Page_Load(object sender, EventArgs e)
    {
        img.ImageUrl ="image/wq.jpg";
    }
    //图片所在的文件夹
    private const string wenjianjia = "image/";
    //添加的图片路径
    private string waterimage = "image/christmas1.jpg";
    //默认图片的路径
    private const string addWaterimage = "image/wq.jpg";

    protected void btnaddText_Click(object sender, EventArgs e)
    {
        //获取上传的文件对象
        HttpPostedFile file = FileUpload1.PostedFile;
        //带路径的全名
        string fullname = file.FileName;
        //只获取文件名,不要路径
        string fillname = fullname.Substring(fullname.LastIndexOf("\\") + 1);
        //重新组合文件名,防止上传的文件名相同时,会覆盖以前上传的文件
        fillname = DateTime.Now.ToString("yyyyMMddhhmmssms") + fillname;
        //把上传的文件对象另存到服务器的文件夹下
        //Server.MapPath(相对路径)把相对路径转换为绝对路径
        file.SaveAs(Server.MapPath("image/" + fillname));

        waterimage = "image/" + fillname;
   
            //组合图片的路径--MapPath:将虚拟路径映射到物理路径
            string path = Request.MapPath(wenjianjia + "wq.jpg");
            Image cover; 
            //File.Exists用于判断相应物理路径中的文件是否存在
            if (File.Exists(path))
            {
                //加载文件
                cover = Image.FromFile(path);//从指定的文件创建image
                //加载水印图片
                Image watermark = Image.FromFile(Request.MapPath(waterimage));
                //实例化画布
                Graphics g = Graphics.FromImage(cover);
               
                g.DrawImage(watermark, new Rectangle(cover.Width - watermark.Width, cover.Height - watermark.Height, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);

                //释放画布
                g.Dispose();
                //释放水印图片
                watermark.Dispose();
            }
            else
            {
                cover = Image.FromFile(Request.MapPath(addWaterimage));
            } 
            Response.ContentType = "image/jpeg";//设置输出类型为JPEG图片
            cover.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);//将修改的图片存入输出流

            //释放cover源图片的所有资源。
            cover.Dispose();
            Response.End();//将当前所有缓冲的输出发送到客户端,停止该页的执行。 --------------------编程问答-------------------- 都走了吗?大家帮帮忙吧
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,