public UpFileResult UpLoadFile(UpFile filedata) { UpFileResult result = new UpFileResult(); string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\service\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } byte[] buffer = new byte[filedata.FileSize]; FileStream fs = new FileStream(path + filedata.FileName, FileMode.Create, FileAccess.Write); int count = 0; while ((count = filedata.FileStream.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, count); } //清空缓冲区 fs.Flush(); //关闭流 fs.Close(); result.IsSuccess = true; return(result); }
/// <summary> /// 上传文件,上传文件的进度只能通过时时获取服务端Read的进度 /// </summary> /// <param name="filepath">文件本地路径</param> /// <returns>上传成功后返回的文件名</returns> public static string UpLoadFile(string filepath, Action <int> action) { ChannelFactory <IFileTransfer> mfileChannelFactory = null; IFileTransfer fileHandlerService = null; try { FileInfo finfo = new FileInfo(filepath); if (finfo.Exists == false) { throw new Exception("文件不存在!"); } mfileChannelFactory = new ChannelFactory <IFileTransfer>("fileendpoint"); fileHandlerService = mfileChannelFactory.CreateChannel(); UpFile uf = new UpFile(); if (AppGlobal.cache.Contains("WCFClientID")) { uf.clientId = AppGlobal.cache.GetData("WCFClientID").ToString(); } uf.UpKey = Guid.NewGuid().ToString(); uf.FileExt = finfo.Extension; uf.FileName = finfo.Name; uf.FileSize = finfo.Length; uf.FileStream = finfo.OpenRead(); if (action != null) { getUpLoadFileProgress(uf.UpKey, action);//获取上传进度条 } UpFileResult result = fileHandlerService.UpLoadFile(uf); //mfileChannelFactory.Close();//关闭会话 if (result.IsSuccess) { return(result.Message); } else { throw new Exception("上传文件失败!"); } } catch (Exception e) { throw new Exception(e.Message + "\n上传文件失败!"); } finally { if (fileHandlerService != null) { (fileHandlerService as IContextChannel).Close(); } if (mfileChannelFactory != null) { mfileChannelFactory.Close(); } } }
/// <summary> /// 上传单个文件, 客户端需要多次调用 /// 客户端控制文件保存路径 /// </summary> /// <param name="filedata">文件信息及stream</param> /// <returns></returns> public UpFileResult UpLoadFile(UpFile filedata) { UpFileResult result = new UpFileResult(); // etc ..\blades\partId string path = Path.Combine(PathManager.Instance.RootPath, filedata.FilePath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } byte[] buffer = new byte[filedata.FileSize]; string fileFullPath = Path.Combine(path, filedata.FileName); FileStream fs = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write); int count = 0; while ((count = filedata.FileStream.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, count); } //清空缓冲区 fs.Flush(); //关闭流 fs.Close(); result.IsSuccess = true; return(result); }
/// <summary> /// 上传文件,到文件缓存目录 /// </summary> /// <param name="filedata"></param> /// <returns></returns> private static UpFileResult UpLoadfilebuffer(UpFile filedata) { if (!Directory.Exists(filebufferpath)) { Directory.CreateDirectory(filebufferpath); } string _filename = DateTime.Now.Ticks.ToString() + filedata.FileExt;//生成唯一文件名,防止文件名相同会覆盖 FileStream fs = new FileStream(filebufferpath + _filename, FileMode.Create, FileAccess.Write); using (fs) { int bufferlen = 4096; int count = 0; byte[] buffer = new byte[bufferlen]; while ((count = filedata.FileStream.Read(buffer, 0, bufferlen)) > 0) { fs.Write(buffer, 0, count); } //清空缓冲区 //fs.Flush(); //关闭流 //fs.Close(); } UpFileResult result = new UpFileResult(); result.IsSuccess = true; result.Message = _filename;//返回保存文件 return(result); }
/// <summary> /// 上传文件,程序升级包 /// </summary> /// <param name="filedata"></param> /// <returns></returns> private static UpFileResult UpLoadUpgrade(UpFile filedata) { UpFileResult result = new UpFileResult(); result.IsSuccess = true; result.Message = "升级包上传成功!"; return(result); }
/// <summary> /// 上传文件,保存到Mongodb /// </summary> /// <param name="filedata"></param> /// <returns></returns> private static UpFileResult UpLoadMongodb(UpFile filedata) { UpFileResult result = new UpFileResult(); result.IsSuccess = true; result.Message = "数据上传到Mongodb成功!"; return(result); }
/// <summary> /// 上传文件 /// </summary> /// <param name="fileName">文件名称</param> /// <param name="projectName">项目名称</param> /// <param name="length">长度</param> /// <param name="sm">文件流</param> /// <param name="message">消息</param> /// <returns></returns> public UpFileResult UpLoadFile(string fileName, long length, Stream sm, out string message) { UpFile upFile = new UpFile { FileName = fileName, ProjectName = _projectName, Size = length, FileStream = sm }; message = string.Empty; return(channel.UpLoadFile(upFile)); }
protected void Button1_OnClick(object sender, EventArgs e) { Tool.UpFile a = new UpFile(); Model.Ydintro hps = new Model.Ydintro() { content = at.Value, imgurl = a.upFileName(this.Image1, this.FileUpload1, "../img/Ydintro/") }; _ = BackStages.Upt.UpYdintro(hps) > 0 ? Tool.Tool.Alert("True", "../img/Ydintro/" + Hq.imgurl) : Tool.Tool.Alert("False"); }
protected void Button1_OnClick(object sender, EventArgs e) { Tool.UpFile a = new UpFile(); Model.fangying hps = new Model.fangying() { fangying_text = at.Value, fangying_title = title.Value, fangying_imageurl = a.upFileName(this.Image1, this.FileUpload1, "../img/fangying/") }; _ = BackStages.Upt.UpFy(hps) > 0 ? Tool.Tool.Alert("True", "../img/fangying/" + Hq.fangying_imageurl) : Tool.Tool.Alert("False"); }
private void UpFileEx(string cudir, string name) { FileInfo file = new FileInfo(name); if (file.Exists) { FileStream stream = new FileStream(name, FileMode.Open, FileAccess.Read); Re: long key = DateTime.Now.Ticks; if (UpFileList.ContainsKey(key)) { System.Threading.Thread.Sleep(1); goto Re; } UpFileList.Add(key, stream); string upfilename = System.IO.Path.Combine(cudir, file.Name); UpFile upfile = new UpFile() { FullName = upfilename, Size = stream.Length, UpKey = key, }; SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress)); } else { DirectoryInfo dir = new DirectoryInfo(name); if (dir.Exists) { string fullname = System.IO.Path.Combine(cudir, dir.Name); PackHandler.NewDir ndir = new PackHandler.NewDir() { DirName = fullname }; SocketManager.Send(BufferFormatV2.FormatFCA(ndir, Deflate.Compress)); foreach (var item in dir.GetFileSystemInfos()) { UpFileEx(fullname, item.FullName); } } } }
protected void Page_Load(object sender, EventArgs e) { string r = ""; SessionUserValidate iv = SysValidateBll.ValidateSession(); B_FixecImgBll bmib = new B_FixecImgBll(); if (iv.f) { HttpFileCollection files = Request.Files; string sid = Request.QueryString["sid"]; //string fixer = Request.QueryString["fixer"]; //string fdate = Request.QueryString["fdate"]; //string ps = Request.QueryString["ps"]; // string bcode = Request.QueryString["bcode"]; string newname = DateTime.Now.ToString("yyyyMMddhhmmssfff"); UpFile uf = new UpFile(); ArrayList efile = new ArrayList(); B_FixecImg spi = new B_FixecImg(); string url = "/UpFile/ImageFixed/"; string ur = uf.UpImage(files[0], newname, url, 1024000); if (ur.Length > 1) { spi.sid = sid; spi.maker = iv.u.ename; spi.fixer = iv.u.ename; spi.fdate = DateTime.Now.ToString(); spi.ps = ""; spi.domain = "p"; spi.url = url + ur; spi.cdate = DateTime.Now.ToString(); bmib.Delete(" and sid='" + sid + "'"); if (bmib.Add(spi) > 0) { //BaseSet.WorkFlowManage.EventBtnDo.FireEventBtn(sid, bcode, "1", "安装完成"); r = "S"; } else { r = "F"; } } else { r = ur; } } else { r = iv.badstr; } Response.Write("{ msg:'" + r + "'}"); Response.End(); }
public string Imports() { JsonData d = new JsonData(); string r = ""; SessionUserValidate iv = SysValidateBll.ValidateSession(); if (iv.f) { string fname = Request["fname"]; string tid = Request["tid"]; HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; string gurl = ""; string newname = DateTime.Now.ToString("yyyyMMddhhmmssfff"); UpFile uf = new UpFile(); string url = "/Image/LogoFile/"; if (files[0].ContentLength > 0) { string ur = uf.UpImage(files[0], newname, url, 10240000); if (ur.Length > 1) { gurl = url + ur; if (stb.UpImg(gurl, fname, Convert.ToInt32(tid))) { r = "S"; } else { r = "F"; } } else { r = "F"; } } else { if (stb.UpImg("", fname, Convert.ToInt32(tid))) { r = "S"; } else { r = "F"; } } } else { r = "F"; } return("{ msg:'" + r + "'}"); }
protected void Button1_OnClick(object sender, EventArgs e) { Tool.UpFile a = new UpFile(); Model.tuandui hps = new Model.tuandui() { name = name.Text, intof = intof.Value, iamgeurl = a.upFileName(this.Image1, this.FileUpload1, "../img/tuandui/"), title = Title.Text }; _ = BackStages.Upt.UpTD(hps) > 0 ? Tool.Tool.Alert("True", "../img/fangying/" + Hq.iamgeurl) : Tool.Tool.Alert("False"); }
protected void Button1_OnClick(object sender, EventArgs e) { Tool.UpFile a = new UpFile(); Model.About hps = new Model.About() { about_linkman = Name.Text, about_phone = Phone.Text, about_site = dis.Text, about_siteurl = a.upFileName(Image1, this.FileUpload1, "../img/about/") }; _ = BackStages.Upt.UpAbout(hps) > 0 ? Tool.Tool.Alert("True", "about/" + Hq.about_siteurl) : Tool.Tool.Alert("False"); }
protected void Page_Load(object sender, EventArgs e) { string r = ""; SessionUserValidate iv = SysValidateBll.ValidateSession(); B_PayImgBll bmib = new B_PayImgBll(); if (iv.f) { string ptype = "o"; HttpFileCollection files = Request.Files; string sid = Request.QueryString["sid"]; string imgms = Request.QueryString["imgms"]; if (Request.QueryString["ptype"] != null) { ptype = Request.QueryString["ptype"].ToString(); } string newname = DateTime.Now.ToString("yyyyMMddhhmmssfff"); UpFile uf = new UpFile(); ArrayList efile = new ArrayList(); B_PayImg spi = new B_PayImg(); string url = "/UpFile/ImageMeasure/"; string ur = uf.UpImage(files[0], newname, url, 10240000); if (ur.Length > 1) { spi.sid = sid; spi.maker = iv.u.ename; spi.remark = imgms; spi.url = url + ur; spi.ptype = ptype; spi.cdate = DateTime.Now.ToString(); if (bmib.Add(spi) > 0) { r = "S"; } else { r = "F"; } } else { r = ur; } } else { r = iv.badstr; } Response.Write("{ msg:'" + r + "'}"); Response.End(); }
public List <ImageInfo> UploadFiles(string containerName) { string thumbnailContainerName = HttpContext.Current.Request.QueryString["thumb"]; if (thumbnailContainerName == "") { thumbnailContainerName = THUMBNAIL_CONTAINER_HEADER + containerName; } string sWidth = HttpContext.Current.Request.QueryString["w"]; string sHeight = HttpContext.Current.Request.QueryString["h"]; int thumbsWidth = (sWidth == "") ? 150 : int.Parse(sWidth); int thumbsHeight = (sHeight == "") ? 150 : int.Parse(sHeight); List <UpFile> upFiles = new List <UpFile>(); List <UpFile> thumbFiles = new List <UpFile>(); HttpFileCollection postedFiles = HttpContext.Current.Request.Files; int postedFilesCount = postedFiles.Count; for (int i = 0; i < postedFilesCount; i++) { HttpPostedFile postedFile = postedFiles[i]; if (postedFile.ContentType.Contains("image")) { var instructions = new Instructions { Width = thumbsWidth, Height = thumbsHeight, Mode = FitMode.Crop, Scale = ScaleMode.Both }; string fileName = FileService.getFileName(postedFile.FileName); if (fileName != "") { int fileLen = postedFile.ContentLength; byte[] input = new byte[fileLen]; Stream fileStream = postedFile.InputStream; fileStream.Read(input, 0, fileLen); fileStream.Position = 0; UpFile upFile = new UpFile(fileName, fileStream, fileLen); upFiles.Add(upFile); MemoryStream thumbStream = new MemoryStream(); ImageBuilder.Current.Build(new ImageJob(postedFile, thumbStream, instructions)); thumbStream.Position = 0; UpFile thumbFile = new UpFile(fileName, thumbStream, (int)thumbStream.Length); thumbFiles.Add(thumbFile); } } } return(FileService.Upload(upFiles, thumbFiles, containerName.ToLower(), thumbnailContainerName)); }
protected void Page_Load(object sender, EventArgs e) { string r = ""; SessionUserValidate iv = SysValidateBll.ValidateSession(); B_GroupProductionBll bmib = new B_GroupProductionBll(); BusiInvTempBll bitb = new BusiInvTempBll(); VProductionsBll vpb = new VProductionsBll(); if (iv.f) { HttpFileCollection files = Request.Files; string sid = Request.QueryString["sid"]; string gnum = Request.QueryString["gnum"]; string ptype = Request.QueryString["ptype"]; string gurl = ""; string newname = DateTime.Now.ToString("yyyyMMddhhmmssfff"); UpFile uf = new UpFile(); string url = "/UpFile/ImageRemark/"; string ur = uf.UpImage(files[0], newname, url, 10240000); if (ur.Length > 1) { gurl = url + ur; if (bmib.UpRemarkImg(sid, Convert.ToInt32(gnum), gurl, ptype)) { //VProductions vps = new VProductions(); //vps.htmtext = bitb.MgItemProductionHtml(sid, Convert.ToInt32(gnum), "0006"); //vps.gnum = Convert.ToInt32(gnum); //vps.vtype = "s"; //vps.sid = sid; //vps.id = sid + gnum + "s"; //vpb.Add(vps); r = "S"; } else { r = "F"; } } else { r = ur; } } else { r = iv.badstr; } Response.Write("{ msg:'" + r + "'}"); Response.End(); }
/// <summary> /// 上传文件,有进度显示 /// </summary> /// <param name="filepath">文件本地路径</param> /// <param name="action">进度0-100</param> /// <returns>上传成功后返回的文件名</returns> public string UpLoadFile(string filepath, Action <int> action) { IFileTransfer fileHandlerService = null; try { FileInfo finfo = new FileInfo(filepath); if (finfo.Exists == false) { throw new Exception("文件不存在!"); } fileHandlerService = mfileChannelFactory.CreateChannel(); UpFile uf = new UpFile(); uf.clientId = mConn == null ? "" : mConn.ClientID; uf.UpKey = Guid.NewGuid().ToString(); uf.FileExt = finfo.Extension; uf.FileName = finfo.Name; uf.FileSize = finfo.Length; uf.FileStream = finfo.OpenRead(); if (action != null) { getupdownprogress(uf.FileStream, uf.FileSize, action);//获取进度条 } UpFileResult result = new UpFileResult(); result = fileHandlerService.UpLoadFile(uf); if (result.IsSuccess) { return(result.Message); } else { throw new Exception("上传文件失败!"); } } catch (Exception e) { throw new Exception(e.Message + "\n上传文件失败!"); } finally { if (fileHandlerService != null) { (fileHandlerService as IContextChannel).Abort(); } } }
protected void Button1_OnClick(object sender, EventArgs e) { Tool.UpFile u = new UpFile(); Model.product a = new Model.product() { id = i, product_imageurl = u.upFileName(this.FileUpload1, "../img/product/"), product_name = product_name.Text, product_intro = product_intro.Text, product_price = int.Parse(product_price.Text), product_content = product_content.Value }; _ = BackStages.List <Model.product> .Getproduct(a) > 0 ? Tool.Tool.Alert("True", "../img/product/" + Hq.product_imageurl) : Tool.Tool.Alert("False"); }
private void listView1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string str = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); FileInfo file = new FileInfo(str); if (file.Exists) { FileStream stream = new FileStream(str, FileMode.Open, FileAccess.Read); Re: long key = DateTime.Now.Ticks; if (UpFileList.ContainsKey(key)) { System.Threading.Thread.Sleep(1); goto Re; } UpFileList.Add(key, stream); string upfilename = CurrentDir + file.Name; if (CurrentDir[CurrentDir.Length - 1] != '\\') { upfilename = CurrentDir + "\\" + file.Name; } UpFile upfile = new UpFile() { FullName = upfilename, Size = stream.Length, UpKey = key, }; SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress)); } } else if (e.Data.GetDataPresent(DataFormats.Text)) { MessageBox.Show((e.Data.GetData(DataFormats.Text)).ToString(), "提示信息", MessageBoxButtons.OK); } }
/// <summary> /// 上传文件 /// </summary> /// <param name="filedata"></param> /// <returns></returns> public static UpFileResult UpLoadFile(UpFile filedata) { try { if (WcfGlobal.IsDebug) { ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]准备上传文件..."); //获取进度 getupdownprogress(filedata.FileStream, filedata.FileSize, (delegate(int _num) { ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件进度:%" + _num); })); } UpFileResult result = new UpFileResult(); if (filedata.FileType == 0)//0:filebuffer目录 1:Upgrade升级包 2:Mongodb { result = UpLoadfilebuffer(filedata); } else if (filedata.FileType == 1) { result = UpLoadUpgrade(filedata); } else if (filedata.FileType == 2) { result = UpLoadMongodb(filedata); } else { result = UpLoadfilebuffer(filedata); } if (WcfGlobal.IsDebug) { ShowHostMsg(Color.Green, DateTime.Now, "客户端[" + filedata.clientId + "]上传文件完成"); } return(result); } catch (Exception err) { //记录错误日志 EFWCoreLib.CoreFrame.EntLib.ZhyContainer.CreateException().HandleException(err, "HISPolicy"); UpFileResult result = new UpFileResult(); result.IsSuccess = false; return(result); } }
protected void Button1_OnClick(object sender, EventArgs e) { Tool.UpFile a = new UpFile(); hp hps = new hp() { hq_name = Name.Text, hq_emil = emlia.Text, hq_fax = Fox.Text, hq_phone = Phone.Text, hq_site = dis.Text, Img_url = a.upFileName(Image1, this.FileUpload1, "../img/") }; _ = BackStages.Upt.UptHp(hps) > 0 ? Tool.Tool.Alert("True", Hq.Img_url) : Tool.Tool.Alert("False"); }
protected void Page_Load(object sender, EventArgs e) { string r = ""; B_ProductionItemBll bpib = new B_ProductionItemBll(); SessionUserValidate iv = SysValidateBll.ValidateSession(); if (iv.f) { HttpFileCollection files = Request.Files; ExcleHelper eh = new ExcleHelper(); string newname = DateTime.Now.ToString("yyyyMMddhhmmssfff"); UpFile uf = new UpFile(); ArrayList efile = new ArrayList(); string url = "/UpFile/ImageMeasure/"; string ur = uf.UpXls(files[0], newname, url, 10240000); if (ur.Length > 1) { string furl = url + ur; string msg = ""; DataTable dt = eh.GetExcelTableByOleDB(furl, "SAP生产统计", true, ref msg); if (msg == "") { if (bpib.UpdateWorkLine(dt) > 0) { r = "S"; } else { r = "F"; } } else { r = "F"; } } else { r = ur; } } else { r = iv.badstr; } Response.Write("{ msg:'" + r + "'}"); Response.End(); }
public async Task <UpFile> StoreFileAsync( string path, Stream content, string contentType = null, string fileName = null, Dictionary <string, string> metadata = null) { this.CheckIfIsInitialized(); var container = this._client.GetContainerReference(this._containerName); var blockBlob = container.GetBlockBlobReference(path); if (!string.IsNullOrEmpty(contentType)) { blockBlob.Properties.ContentType = contentType; } if (!string.IsNullOrEmpty(fileName)) { blockBlob.Properties.ContentDisposition = "attachment; filename=" + fileName; } if (metadata != null) { foreach (var md in metadata) { blockBlob.Metadata.Add(md); } } content.Position = 0; try { await blockBlob.UploadFromStreamAsync(content); } catch (Exception ex) { } var result = new UpFile() { FullPath = blockBlob.Uri.ToString(), Name = blockBlob.Name, Size = blockBlob.StreamWriteSizeInBytes, }; return(result); }
protected void Page_Load(object sender, EventArgs e) { string r = ""; SessionUserValidate iv = SysValidateBll.ValidateSession(); B_SelectProduceImgBll bspib = new B_SelectProduceImgBll(); if (iv.f) { HttpFileCollection files = Request.Files; string sid = Request.QueryString["sid"]; string spname = Request.QueryString["spname"]; string newname = DateTime.Now.ToString("yyyyMMddhhmmssfff"); UpFile uf = new UpFile(); ArrayList efile = new ArrayList(); B_SelectProduceImg spi = new B_SelectProduceImg(); string url = "/UpFile/ImageMeasure/"; string ur = uf.UpImage(files[0], newname, url, 10240000); if (ur.Length > 1) { spi.sid = sid; spi.xsid = CommonBll.GetSid(); spi.maker = iv.u.ename; spi.xpname = spname; spi.xpurl = url + ur; spi.cdate = DateTime.Now.ToString(); if (bspib.Add(spi) > 0) { r = "S"; } else { r = "F"; } } else { r = ur; } } else { r = iv.badstr; } Response.Write("{ msg:'" + r + "'}"); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { string r = ""; SessionUserValidate iv = SysValidateBll.ValidateSession(); B_AfterProductionImgBll bitb = new B_AfterProductionImgBll(); if (iv.f) { HttpFileCollection files = Request.Files; string sid = Request.QueryString["sid"]; string gnum = Request.QueryString["gnum"]; string gurl = ""; string newname = DateTime.Now.ToString("yyyyMMddhhmmssfff"); UpFile uf = new UpFile(); string url = "/UpFile/ImageAfter/"; string ur = uf.UpImage(files[0], newname, url, 10240000); if (ur.Length > 1) { gurl = url + ur; B_AfterProductionImg bai = new B_AfterProductionImg(); bai.gnum = Convert.ToInt32(gnum); bai.sid = sid; bai.url = gurl; bai.maker = iv.u.ename; bai.cdate = DateTime.Now.ToString(); if (bitb.Add(bai) > 0) { r = "S"; } else { r = "F"; } } else { r = ur; } } else { r = iv.badstr; } Response.Write("{ msg:'" + r + "'}"); Response.End(); }
private void _Up_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filename = openFileDialog1.FileName; FileInfo file = new FileInfo(filename); if (file.Exists) { FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read); Re: long key = DateTime.Now.Ticks; if (UpFileList.ContainsKey(key)) { System.Threading.Thread.Sleep(1); goto Re; } UpFileList.Add(key, stream); string upfilename = CurrentDir + file.Name; if (CurrentDir[CurrentDir.Length - 1] != '\\') { upfilename = CurrentDir + "\\" + file.Name; } UpFile upfile = new UpFile() { FullName = upfilename, Size = stream.Length, UpKey = key, }; SocketManager.Send(BufferFormatV2.FormatFCA(upfile, Deflate.Compress)); } } }
/// <summary> /// 上传单个文件到服务器 /// </summary> /// <param name="partId">工件标识</param> /// <param name="filefullPath">文件全路径名</param> /// <param name="filePath">相对路径,baldes\partId或者programs</param> /// <returns></returns> private bool UpFileToServer(string partId, string filefullPath, string filePath) { using (Stream fs = new FileStream(filefullPath, FileMode.Open, FileAccess.Read)) { UpFile fileData = new UpFile(); fileData.FileName = Path.GetFileName(filefullPath); fileData.FileSize = fs.Length; fileData.FilePath = filePath; fileData.FileStream = fs; fileData.PartId = partId; UpFileResult ures = _partConfigService.UpLoadFile(fileData); //if (ures.IsSuccess) //{ // Debug.WriteLine("File up ok"); //} return(ures.IsSuccess); } }
protected void Button1_OnClick(object sender, EventArgs e) { Tool.UpFile a = new UpFile(); if (OPwd.Text == Hq.pwd && NPwd.Text == Pwd.Text) { admin hps = new admin() { pwd = Pwd.Text, name = Name.Text, imurl = a.upFileName(this.FileUpload1, "../img/admin/") }; _ = BackStages.List <Model.admin> .GetAdmin(hps) > 0 ? Tool.Tool.Alert("True", "../img/admin/" + Hq.imurl) : Tool.Tool.Alert("False"); } else { Tool.Tool.Alert("某项输入不合法"); } }
protected void Page_Load(object sender, EventArgs e) { string r = ""; SessionUserValidate iv = SysValidateBll.ValidateSession(); B_ServiceImgBll bmib = new B_ServiceImgBll(); if (iv.f) { HttpFileCollection files = Request.Files; string sid = Request.QueryString["sid"]; string ptype = Request.QueryString["ptype"]; string newname = DateTime.Now.ToString("yyyyMMddhhmmssfff"); UpFile uf = new UpFile(); string url = "/UpFile/ImageService/"; string ur = uf.UpImage(files[0], newname, url, 10240000); if (ur.Length > 1) { B_ServiceImg bsi = new B_ServiceImg(); bsi.iurl = url + ur; bsi.sid = sid; bsi.itype = ptype; bsi.maker = iv.u.ename; bsi.cdate = DateTime.Now.ToString(); if (bmib.Add(bsi) > 0) { r = "S"; } else { r = "F"; } } else { r = ur; } } else { r = iv.badstr; } Response.Write("{ msg:'" + r + "'}"); Response.End(); }