C#上传图片源码

来源:互联网 发布:linux创建用户脚本 编辑:程序博客网 时间:2024/05/13 15:25


                Random seed = new Random();
                string oriFileName = _file.FileName.Trim();
                if (oriFileName.Length <= 0)
                {
                    return;
                }
                string oriFileExtName = Path.GetExtension(oriFileName);
                string saveFileName = string.Format("{0}{1}{2}", DateTime.Now.ToString("yyyyMMddHHmmssfff"), seed.Next(1000, 10000), oriFileExtName);
                string filePath = Server.MapPath(string.Format("~/Upload/{0}", saveFileName));

                try
                {
                    if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                    }
                    _file.SaveAs(filePath);
                    Common.PageMethods.Script(this, string.Format("parentShowFileName(\"{0}\",\"{1}\")", oriFileName, saveFileName));
                }
                catch (Exception err)
                {
                    Common.PageMethods.Script(this, string.Format("parentShowError(\"{0}\")", err.Message));
                }

0 0
原创粉丝点击