C# 通过用application.startuppath+tmp创建图片存储临时虚拟文件

来源:互联网 发布:沉降观测软件 编辑:程序博客网 时间:2024/06/11 10:33

ImgSource为文件的物理存储路径。

if (System.IO.File.Exists(ImgSource))  //先判断文件是否真实存在

            {
                //生成临时文件名
                string strTmpFile = Guid.NewGuid().ToString().Replace("-", "");
                string strImageExtFileName = ImgSource;
                strImageExtFileName = strImageExtFileName.Substring(strImageExtFileName.LastIndexOf("."));
                strTmpFile += strImageExtFileName;

                //生成临时路径
                string strAppPath = AppDomain.CurrentDomain.BaseDirectory;
                if(!Directory.Exists(strAppPath + "tmp"))
                {
                    Directory.CreateDirectory(strAppPath+"tmp");
                }
                //复制图片文件
                File.Copy(ImgSource,string.Format("{0}tmp\\{1}",strAppPath,strTmpFile));
            }
0 0
原创粉丝点击