/// <summary> /// 下载文件 /// </summary> /// <param name="fileName"></param> /// <returns></returns> public ActionResult DownloadFile(string fileName) { if (_Request == null) { _Request = Request; } try { var fs = new System.IO.FileStream(HttpUtility.UrlDecode(fileName, Encoding.UTF8), FileMode.Open); if (fs != null) { string ext = FileOperateHelper.GetFileExt(fileName); string tempfn = Path.GetFileName(fileName); return(File(fs, FileOperateHelper.GetHttpMIMEContentType(ext), tempfn)); } else { return(Content("<script>alert('找不到此文件!');</script>")); } } catch (Exception ex) { return(Content("<script>alert('异常:" + ex.Message + "');</script>")); } }
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { if (target == BuildTarget.iPhone) { string plugInFolderPath = System.IO.Path.Combine(Application.dataPath, PLUG_IN_FOLDER_RELATIVE_PATH); string destinationPath = System.IO.Path.Combine(pathToBuiltProject, PLUG_IN_FOLDER_RELATIVE_PATH); List <ProjectItemInformation> items = new List <ProjectItemInformation>(); FileOperateHelper.CopyFolder(plugInFolderPath, destinationPath); items.AddRange(XcodeUtility.GetItemsFromDirectory(destinationPath, CLASS_FOLDER_NAME, true)); items.Add(new FrameworkFileInformation() { FrameworkType = FrameworkType.StoreKit, FileType = ProjectFileType.Framework }); XcodeModifyHelper.ModifyXcodeProject(items, pathToBuiltProject); XcodeModifyHelper.AddEntityToInfoPlist(pathToBuiltProject, "UIViewControllerBasedStatusBarAppearance", false); AddStoreHelperCode(pathToBuiltProject); XcodeModifyHelper.AddEntityToInfoPlist(pathToBuiltProject, "CFBundleDevelopmentRegion", "zh_CN"); //AddPlugInFiles(xcodeProjectClassGroupPath, pathToBuiltProject); //AddStoreKitFramework(pathToBuiltProject); //AddStoreHelperCode(pathToBuiltProject); } }
/// <summary> /// 下载附件 /// </summary> /// <param name="attachId">附件Id</param> /// <returns></returns> public ActionResult DownloadAttachment(Guid attachId) { if (_Request == null) { _Request = Request; } string errMsg = string.Empty; Sys_Attachment attachment = CommonOperate.GetEntityById <Sys_Attachment>(attachId, out errMsg); if (attachment != null) { try { string tempFile = string.Format("{0}{1}", Globals.GetWebDir(), attachment.FileUrl.ObjToStr().Replace(Globals.GetBaseUrl(), string.Empty)); if (WebConfigHelper.GetAppSettingValue("IsLinux") != "true") { tempFile = tempFile.Replace("/", "\\"); } string ext = FileOperateHelper.GetFileExt(tempFile); var fs = new System.IO.FileStream(tempFile, FileMode.Open); if (fs != null) { return(File(fs, FileOperateHelper.GetHttpMIMEContentType(ext), Url.Encode(attachment.FileName))); } } catch (Exception ex) { return(Content("<script>alert('异常:" + ex.Message + "');</script>")); } } return(Content("<script>alert('找不到此文件!');</script>")); }
/// <summary> /// 下载附件 /// </summary> /// <param name="attachId">附件Id</param> /// <returns></returns> public ActionResult DownloadAttachment(Guid attachId) { if (_Request == null) { _Request = Request; } string errMsg = string.Empty; Sys_Attachment attachment = CommonOperate.GetEntityById <Sys_Attachment>(attachId, out errMsg); if (attachment != null) { try { string pathFlag = System.IO.Path.DirectorySeparatorChar.ToString(); string tempFile = string.Format("{0}{1}", Globals.GetWebDir(), attachment.FileUrl.ObjToStr().Replace(Globals.GetBaseUrl(), string.Empty)); tempFile = tempFile.Replace("/", pathFlag); string ext = FileOperateHelper.GetFileExt(tempFile); var fs = new System.IO.FileStream(tempFile, FileMode.Open); if (fs != null) { string tempfn = attachment.FileName; return(File(fs, FileOperateHelper.GetHttpMIMEContentType(ext), tempfn)); } } catch (Exception ex) { return(Content("<script>alert('异常:" + ex.Message + "');</script>")); } } return(Content("<script>alert('找不到此文件!');</script>")); }
public ActionResult UploadTempImportFile(HttpPostedFileBase file) { if (file == null) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } string message = string.Empty; try { string fileSize = FileOperateHelper.FileSize(file.ContentLength); string fileType = Path.GetExtension(file.FileName); //保存文件 UploadFileManager.httpContext = _Request.RequestContext.HttpContext; string filePath = UploadFileManager.SaveAs(file, string.Empty, "Temp"); if (string.IsNullOrWhiteSpace(filePath)) { message = "上传失败!"; } return(Json(new { Success = string.IsNullOrEmpty(message), Message = message, FilePath = filePath }, "text/plain")); } catch (Exception ex) { message = string.Format("上传失败,异常:{0}", ex.Message); return(Json(new ReturnResult { Success = false, Message = message }, "text/plain")); } }
private static string AddGroup(ref string projectContent, ProjectGroupInformation groupInfo) { string pattern = "([A-Z0-9]+) /\\* " + Regex.Escape(groupInfo.GroupName) + " \\*/ = \\{\n[ \t]+isa = PBXGroup;\n[ \t]+children = \\(\n((?:.|\n)+?)\\);"; Match match = Regex.Match(projectContent, pattern); if (match.Success) { Debug.Log("The group is Already exists."); return(match.Groups[1].Value); } else { pattern = "/\\* Begin PBXGroup section \\*/((?:.|\n)+?)/\\* End PBXGroup section \\*/"; match = Regex.Match(projectContent, pattern); string groupGuid = GenerateGUID(); string addString = string.Empty; if (string.IsNullOrEmpty(groupInfo.GroupPath)) { addString = string.Format("{0}{1} /* {2} */ = {3}{0}\tisa = PBXGroup;{0}\tchildren = ({0}\t);{0}\tname = {2};{0}\tsourceTree = \"<group>\";{0}{4};", "\n\t\t\t\t", groupGuid, groupInfo.GroupName, "{", "}"); } else { string path = groupInfo.IsRoot ? FileOperateHelper.GetRelativePathFromAbsolutePath(projectPath, groupInfo.GroupPath) : groupInfo.GroupPath; addString = string.Format("{0}{1} /* {2} */ = {4}{0}\tisa = PBXGroup;{0}\tchildren = ({0}\t);{0}\tname={2};{0}\tpath = {3};{0}\tsourceTree = \"<group>\";{0}{5};", "\n\t\t\t\t", groupGuid, groupInfo.GroupName, path, "{", "}"); } projectContent = projectContent.Substring(0, match.Groups[1].Index) + addString + projectContent.Substring(match.Groups[1].Index); return(groupGuid); } }
/// <summary> /// 处理请求 /// </summary> /// <param name="context">上下文对象</param> public void ProcessRequest(HttpContext context) { if (UserInfo.GetCurretnUser(context) != null) { string path = string.Empty; if (context.Request.RawUrl.Contains("?")) { string temp = context.Request.RawUrl.Substring(0, context.Request.RawUrl.IndexOf("?")); path = context.Server.MapPath(temp); } else { path = context.Server.MapPath(context.Request.RawUrl); } try { string ext = FileOperateHelper.GetFileExt(path); context.Response.HeaderEncoding = Encoding.UTF8; context.Response.ContentEncoding = Encoding.UTF8; context.Response.ContentType = FileOperateHelper.GetHttpMIMEContentType(ext); context.Response.WriteFile(path); } catch (Exception ex) { context.Response.Write(string.Format("异常:{0}", ex.Message)); } } else { context.Response.Write("未登录前不能访问该资源,请登录后访问。<a href='/User/Login.html'>登录</a>"); } }
private static void AddFrameworkConfiguration(ref string projectContent, string frameworkPath) { string directoryPath = System.IO.Path.GetDirectoryName(frameworkPath); string relativePath = FileOperateHelper.GetRelativePathFromAbsolutePath(projectPath, directoryPath); string newValue = "\"\\\"$(SRCROOT)/" + relativePath + "\\\"\""; //Debug.Log("the new value is: " + newValue); ModifyBuildSetting(ref projectContent, ProjectSettingType.FrameworkSearchPath, newValue, ModifyType.Append); }
private void UpdateFiles() { Files.Clear(); List <string> list = FileOperateHelper.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\data", "*.txt"); list.ForEach(x => Files.Add(new File() { Path = x, Name = System.IO.Path.GetFileNameWithoutExtension(x) })); }
private static List <ProjectItemInformation> GetNdFrameworks(string projectPath) { string frameworkPath = System.IO.Path.Combine(Application.dataPath, ND_FRAMEWORK_RELATIVE_PATH); string destinationPath = System.IO.Path.Combine(projectPath, ND_FRAMEWORK_RELATIVE_PATH); FileOperateHelper.CopyFolder(frameworkPath, destinationPath); string parentGroup = "Frameworks"; return(XcodeUtility.GetItemsFromDirectory(destinationPath, parentGroup, true)); }
public static List <ProjectItemInformation> GetNdResource(string projectPath) { string resourcePath = System.IO.Path.Combine(Application.dataPath, ND_RESOURCE_BUNDLE_RELATIVE_PATH); string destinationPath = System.IO.Path.Combine(projectPath, ND_RESOURCE_BUNDLE_RELATIVE_PATH); FileOperateHelper.CopyFolder(resourcePath, destinationPath); string parentGroup = "Resources"; return(XcodeUtility.GetItemsFromDirectory(destinationPath, parentGroup, true)); }
private static List <ProjectItemInformation> GetNativeCode(string projectPath) { string nativePath = System.IO.Path.Combine(Application.dataPath, ND_NATIVE_SOURCE_FOLDER_PATH); string destinationPath = System.IO.Path.Combine(projectPath, ND_NATIVE_SOURCE_FOLDER_PATH); FileOperateHelper.CopyFolder(nativePath, destinationPath); string parentGroup = "Classes"; return(XcodeUtility.GetItemsFromDirectory(destinationPath, parentGroup, true)); }
public async Task <ApiResult <ImportViolationOutputDto> > ImportViolations([FromForm] ImportViolationInputDto input) { try { var batchInfo = await _batchInfoRepository.FirstOrDefaultAsync(x => x.Id == input.BatchId); if (batchInfo == null) { return(new ApiResult <ImportViolationOutputDto>().Error("批次信息不存在")); } List <BatchTableModelDto> list; using (var fs = input.File.OpenReadStream()) { list = GetExcelData(fs, input.File.FileName); } var errors = await CheckError(list); await QueryViolationInfo(list, batchInfo); list.ForEach(x => { x.Uniquecode = CommonHelper.GenerateViolationCode(x.车牌号, x.违章时间, x.违章原因); x.BatchId = input.BatchId; x.CreateUserId = AbpSession.UserId; x.CreateUserName = AbpSession.UserName; x.WebSiteId = AbpSession.WebSiteId; }); var repeats = await CheckRepeat(list, input.BatchId); var fileName = $"{Guid.NewGuid().ToString("N")}{Path.GetExtension(input.File.FileName)}"; var fullFilePath = Path.Combine(_env.WebRootPath, "UploadFiles", fileName); await FileOperateHelper.SaveStreamToFileAsync(input.File.OpenReadStream(), fullFilePath); var result = new ImportViolationOutputDto { SuccessList = list, ErrorList = errors, FilePath = fileName }; return(new ApiResult <ImportViolationOutputDto>().Success(result)); } catch (Exception ex) { _logger.Error($"ImportViolations:{ex.Message}"); return(new ApiResult <ImportViolationOutputDto>().Error(MessageTipsConsts.SystemBusy)); } }
private void SetUrl2PicBox(string url) { HttpHelper helper = new HttpHelper(); byte[] bytes = helper.DownloadPng(url); //将byte数组转成Image对象 Image img = FileOperateHelper.BytToImg(bytes); img.Save("chart.png", System.Drawing.Imaging.ImageFormat.Png); //把image对象设值到picturebox上 pictureBox1.Image = img; }
private void WriteToLog(Func <string> logMessage) { /* * 修 改 人:Empty(AllEmpty) * QQ 群:327360708 * 博客地址:http://www.cnblogs.com/EmptyFS/ * 修改时间:2015-01-16 * 修改说明:通过Web.config设置IsSaveSubSonicLog来开启是否记录所有执行的SQL语句 *********************************************/ FileOperateHelper.WriteLog("SubSonic", logMessage()); //if (_logger != null) //{ // _logger.Log(logMessage()); //} }
public ActionResult NoiseReport() { ViewBag.pm = 25; //Dictionary<string,string> dictParam = new Dictionary<string, string> {{"department_id","3"},{"fetch_child","0"},{"status","0"} }; Dictionary <string, string> dictParam = new Dictionary <string, string> { { "agentid", "2" } }; //string strJson = "{\"userid\":\"luxiaolin\"}"; string strJson = FileOperateHelper.ReadFile(HttpRuntime.AppDomainAppPath + @"bin\xmlConfig\JsonButtonConfig.txt"); //ViewBag.Result = new MenuManager().Delete(dictParam ); //ViewBag.Result = new MenuManager().Create(strJson, dictParam ); ViewBag.Result = new MenuManager().Get(dictParam); return(View()); }
private void Import() { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); //dlg.FileName = "User.txt"; // Default file name dlg.DefaultExt = ".txt"; // Default file extension dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension if (!System.IO.Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "data")) { System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "data"); } dlg.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "data"; // Show save file dialog box var result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { try { this.SelectedIndex = -1; List <string> lines = FileOperateHelper.ReadFileLines(dlg.FileName); this.Points.Clear(); foreach (var line in lines) { string[] temp = line.Split('#'); if (temp.Count() != 4) { Debug.WriteLine("路径:" + _selectedValue + ",格式不对"); Debug.WriteLine(line); continue; } this.Points.Add(new Point(temp[0], float.Parse(temp[1]), float.Parse(temp[2]), float.Parse(temp[3]))); } } catch (Exception ex) { SoftContext.MainWindow.ShowMessageAsync("导入失败", ex.Message); } } }
public ActionResult UploadTempImage(HttpPostedFileBase file) { if (file == null) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } string message = string.Empty; string imgName = _Request["imgName"].ObjToStr(); try { string fileSize = FileOperateHelper.FileSize(file.ContentLength); string fileType = Path.GetExtension(file.FileName); //保存文件 UploadFileManager.httpContext = _Request.RequestContext.HttpContext; string filePath = UploadFileManager.SaveAs(file, string.Empty, "Temp", imgName); if (!string.IsNullOrEmpty(filePath) && filePath.Substring(0, 1) != "/") { filePath = "/" + filePath; } else { message = "临时图片保存失败!"; } return(Json(new { Success = string.IsNullOrEmpty(message), Message = message, FilePath = filePath }, "text/plain")); } catch (Exception ex) { message = string.Format("图片上传失败,原因:{0}", ex.Message); return(Json(new ReturnResult { Success = false, Message = message }, "text/plain")); } }
private void SaveAs() { //if (FileOperateHelper.IsExists(_selectedValue.ToString())) //{ // var result = System.Windows.MessageBox.Show("文件已存在是否覆盖?", "提示", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question); // if (result == System.Windows.MessageBoxResult.No) // return; //} Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); //dlg.FileName = "User.txt"; // Default file name dlg.DefaultExt = ".txt"; // Default file extension dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension if (!System.IO.Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "data")) { System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "data"); } dlg.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "data"; // Show save file dialog box var result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { try { string content = ""; foreach (var p in Points) { content += p.Name + "#" + p.X + "#" + p.Y + "#" + p.Z + "\r\n"; } FileOperateHelper.WriteFile(dlg.FileName, content, true); UpdateFiles(); } catch (Exception ex) { SoftContext.MainWindow.ShowMessageAsync("保存失败", ex.Message); } } }
private static List <ProjectFileInformation> GetPlugInFilesInformation(string projectGroupPath, string projectFilePath) { string plugInFolderPath = System.IO.Path.Combine(Application.dataPath, PLUG_IN_FOLDER_RELATIVE_PATH); List <string> plugInFiles = FileOperateHelper.GetFiles(plugInFolderPath, new List <string>() { ".h", ".m" }); FileOperateHelper.CopyFiles(plugInFiles, plugInFolderPath, projectGroupPath); List <ProjectFileInformation> files = new List <ProjectFileInformation>(); foreach (string filePath in plugInFiles) { ProjectFileInformation information = new ProjectFileInformation(); information.FileName = System.IO.Path.GetFileName(filePath); information.FilePath = filePath; information.FileType = ProjectFileType.Source; } return(files); //XcodeModifyHelper.ModifyXcodeProject(plugInFiles, projectFilePath, ProjectFileType.Source); }
private void SaveList() { try { if (_selectedValue == null) { SaveAs(); return; } string content = ""; foreach (var p in Points) { content += p.Name + "#" + p.X + "#" + p.Y + "#" + p.Z + "\r\n"; } FileOperateHelper.WriteFile(_selectedValue.ToString(), content, true); SoftContext.MainWindow.ShowMessageAsync("保存成功", "路径:" + _selectedValue.ToString()); }catch (Exception ex) { SoftContext.MainWindow.ShowMessageAsync("保存失败", ex.Message); } }
/// <returns>上传成功返回"",并填充 Model.UploadFile</returns> /// <param name="vid">上传配置模块id,即UploadConfig_Id</param> /// <param name="key">随机key</param> /// <param name="userId">上传者id</param> /// <param name="userName">上传者UserName</param> /// <param name="remotePicUrl">远程图片的url地址</param> /// <param name="m_r">Model.UploadFile</param> /// <returns>上传成功返回"",并填充 Model.UploadFile</returns> public string Upload_RemotePic(int vid, string key, int userId, string userName, string remotePicUrl, UploadFile m_r) { #region 检查参数 //--------------------------------------------------- if (vid < 1 || key.Length < 10) { return("缺少参数:key或sid"); } //--------------------------------------------------- #region 检查登陆 m_r.UserId = userId; m_r.UserName = userName; if (m_r.UserId == 0) { return("您的权限不足!"); } #endregion //--------------------------------------------------- UploadConfig mC = Read_UploadConfig(vid); if (mC.Id != vid) { return("缺少参数:UploadConfig_Id!"); } if (mC.IsPost != 1) { return("系统暂时禁止上传文件2!"); } if (mC.IsEditor != 1) { return("非编辑器类别!"); } mC.UploadType_TypeKey = "image"; #endregion //---------------------------------------------- #region 生成暂时目录 string sCfgSavePath = new Uploader().SavePath; string sSavePath = DirFileHelper.FixDirPath(sCfgSavePath + mC.SaveDir) + DateTime.Now.ToString("yyMM") + "/"; if (!DirFileHelper.CheckSaveDir(sSavePath)) { return("SavePath设置不当:" + sSavePath + ", 或权限不足!"); } string sServerDir = sCfgSavePath + "remote/"; if (!DirFileHelper.CheckSaveDir(sServerDir)) { return("ServerDir设置不当:" + sServerDir + ", 或权限不足!"); } //---------------------------------------------- string sSrcName = StringHelper.Left(DirFileHelper.GetFileName(remotePicUrl), 90); string sFileExt = DirFileHelper.GetFileExtension(sSrcName); //因部部分网站不是标准的jpg、gif扩展名,所以修改下面代码 if (sFileExt.Length > 0) { string sAllowed = ",jpg,gif,png,bmp,"; string sExt = "," + sFileExt.ToLower() + ","; if (sAllowed.IndexOf(sExt) == -1) { sFileExt = "jpg"; } } else { sFileExt = "jpg"; } //---------------------------------------------- string sNewFile = FileOperateHelper.GetRndFileName("." + sFileExt); if (sServerDir.IndexOf(":") < 0) { sServerDir = DirFileHelper.FixDirPath(DirFileHelper.GetMapPath(sServerDir)); } string sNewRoot = System.IO.Path.Combine(sServerDir, sNewFile); #endregion //---------------------------------------------- #region 到暂时目录 try { var wc = new System.Net.WebClient(); wc.DownloadFile(remotePicUrl, sNewRoot); } catch (Exception ex) { //throw ex; return(ex.Message.ToLower()); } if (!DirFileHelper.IsExistFile(sNewRoot)) { return("上传失败"); } #endregion //---------------------------------------------- #region 判断是否真实图片格式,并取得图片宽高 int ww = 0, hh = 0; if (!Uploader.Get_Pic_WW_HH(sNewRoot, out ww, out hh)) { DirFileHelper.DeleteFile(sNewRoot); return("非法格式!不是图片文件。"); } int iMaxSize = mC.PicSize; long iFileSize = DirFileHelper.GetFileSize(sNewRoot); /* * if (iFileSize > iMaxSize) * { * return "上传文件大小超过了限制.最多上传(" + DirFileHelper.FmtFileSize2(iMaxSize) + ")."; * } */ #endregion #region 把上传的暂时文件复制到相关模块目录中 string sNewPath = sSavePath + sNewFile; string orgImg = DirFileHelper.GetFilePathPostfix(sNewPath, "o"); //复制到原始图 DirFileHelper.CopyFile(sNewRoot, orgImg); //删除暂时上传的图片 DirFileHelper.DeleteFile(sNewRoot); //生成相关缩略图 OneMakeThumbImage(sNewPath, mC); #endregion //---------------------------------------------- #region 保存入数据库 m_r.UploadConfig_Id = mC.Id; m_r.JoinName = mC.JoinName; m_r.JoinId = 0; m_r.UserType = mC.UserType; m_r.UserIp = IpHelper.GetUserIp(); m_r.AddDate = DateTime.Now; m_r.InfoText = ""; m_r.RndKey = key; m_r.Name = sNewFile; m_r.Path = sNewPath; m_r.Src = sSrcName; m_r.Ext = sFileExt; m_r.Size = ConvertHelper.Cint0(iFileSize); m_r.PicWidth = ww; m_r.PicHeight = hh; //保存入数据库 Add_UploadFile(m_r); #endregion //------------------------------------ //上传成功,输出结果 return(""); }
public ActionResult UploadAttachment(HttpPostedFileBase[] file, Guid?moduleId, Guid?id, bool isCreateSwf = false) { if (file == null || file.Where(o => o == null).Count() > 0) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } SetRequest(_Request); string attachType = _Request["attachType"].ObjToStr(); UploadFileManager.httpContext = _Request.RequestContext.HttpContext; string message = string.Empty; StringBuilder msg = new StringBuilder(); List <AttachFileInfo> fileMsg = new List <AttachFileInfo>(); foreach (var item in file) { try { string fileSize = FileOperateHelper.FileSize(item.ContentLength); string fileType = Path.GetExtension(item.FileName); string fileName = item.FileName; string pathFlag = "\\"; if (WebConfigHelper.GetAppSettingValue("IsLinux") == "true") { pathFlag = "/"; } int s = fileName.LastIndexOf(pathFlag); if (s >= 0) { fileName = fileName.Substring(s + 1); } //保存文件 string filePath = string.Empty; if (moduleId.HasValue) //表单附件 { filePath = UploadFileManager.SaveAs(item, "Attachment", "Temp"); } else { filePath = UploadFileManager.SaveAs(item, string.Empty); } filePath = filePath.StartsWith("~/") ? filePath : filePath.StartsWith("/") ? "~" + filePath : "~/" + filePath; //swf保存路径 string swfPath = string.Empty; //pdf保存路径 string pdfPath = string.Empty; if (isCreateSwf && !moduleId.HasValue) { //exe路径 string exePath = _Request.RequestContext.HttpContext.Server.MapPath("~/bin/SWFTools/pdf2swf.exe"); //bin路径 string binPath = _Request.RequestContext.HttpContext.Server.MapPath("~/bin/"); if (fileType.Equals(".doc") || fileType.Equals(".docx") || fileType.Equals(".xls") || fileType.Equals(".xlsx") || fileType.Equals(".ppt") || fileType.Equals(".pptx") || fileType.Equals(".pdf")) { //取pdf和swf路径 GetFilePath(out pdfPath, out swfPath); //参数 string[] obj = new string[] { fileType, _Request.RequestContext.HttpContext.Server.MapPath(filePath), _Request.RequestContext.HttpContext.Server.MapPath(pdfPath), _Request.RequestContext.HttpContext.Server.MapPath(swfPath), exePath, binPath }; CreateSwfFile(obj); } } fileMsg.Add(new AttachFileInfo() { AttachFile = filePath, PdfFile = pdfPath, SwfFile = swfPath, FileName = fileName, FileType = fileType, FileSize = fileSize, AttachType = attachType }); } catch (Exception ex) { msg.AppendLine(item.FileName + "上传失败:" + ex.Message); break; } } if (moduleId.HasValue && id.HasValue) //查看页面,直接保存附件 { return(SaveFormAttach(moduleId.Value, id.Value, JsonHelper.Serialize(fileMsg), true)); } return(Json(new { Success = string.IsNullOrEmpty(msg.ToString()), Message = string.IsNullOrEmpty(msg.ToString()) ? "上传成功" : msg.ToString(), FileMsg = fileMsg.Count > 0 ? JsonHelper.Serialize(fileMsg) : string.Empty }, "text/plain")); }
/// <summary> /// 上传附件,兼容非表单附件 /// </summary> /// <param name="file">文件</param> /// <returns></returns> public JsonResult UploadAttachment(IFormFileCollection file) { if (file == null || file.Count() == 0) { return(Json(new ReturnResult { Success = false, Message = "请选择上传文件!" })); } if (_Request == null) { _Request = Request; } SetRequest(_Request); Guid? moduleId = _Request.QueryEx("moduleId").ObjToGuidNull(); //模块Id,针对表单附件 Guid? id = _Request.QueryEx("id").ObjToGuidNull(); //记录Id,针对表单附件 bool isCreateSwf = _Request.QueryEx("isCreateSwf").ObjToBool(); //是否创建SWF文件 string attachType = _Request.QueryEx("attachType").ObjToStr(); //附件类型 string message = string.Empty; StringBuilder msg = new StringBuilder(); List <AttachFileInfo> fileMsg = new List <AttachFileInfo>(); foreach (var item in file) { try { string fileSize = FileOperateHelper.FileSize(item.Length); string fileType = Path.GetExtension(item.FileName); string fileName = item.FileName; string pathFlag = System.IO.Path.DirectorySeparatorChar.ToString(); int s = fileName.LastIndexOf(pathFlag); if (s >= 0) { fileName = fileName.Substring(s + 1); } //保存文件 string filePath = string.Empty; if (moduleId.HasValue) //表单附件 { filePath = UploadFileManager.SaveAs(item, "Attachment", "Temp"); } else { filePath = UploadFileManager.SaveAs(item, "Temp"); } filePath = filePath.StartsWith("~/") ? filePath : filePath.StartsWith("/") ? "~" + filePath : "~/" + filePath; //swf保存路径 string swfPath = string.Empty; //pdf保存路径 string pdfPath = string.Empty; if (isCreateSwf && !moduleId.HasValue) { //exe路径 string exePath = WebHelper.MapPath("~/bin/SWFTools/pdf2swf.exe"); //bin路径 string binPath = WebHelper.MapPath("~/bin/"); if (fileType.Equals(".doc") || fileType.Equals(".docx") || fileType.Equals(".xls") || fileType.Equals(".xlsx") || fileType.Equals(".ppt") || fileType.Equals(".pptx") || fileType.Equals(".pdf")) { //取pdf和swf路径 SystemOperate.GetSwfFilePath(out pdfPath, out swfPath); //参数 string[] obj = new string[] { fileType, WebHelper.MapPath(filePath), WebHelper.MapPath(pdfPath), WebHelper.MapPath(swfPath), exePath, binPath }; SystemOperate.CreateSwfFile(obj); } } fileMsg.Add(new AttachFileInfo() { AttachFile = filePath, PdfFile = pdfPath, SwfFile = swfPath, FileName = fileName, FileType = fileType, FileSize = fileSize, AttachType = attachType }); } catch (Exception ex) { msg.AppendLine(item.FileName + "上传失败:" + ex.Message); break; } } if (moduleId.HasValue && moduleId.Value != Guid.Empty && id.HasValue && id.Value != Guid.Empty) //查看页面,直接保存附件 { return(SaveFormAttach(moduleId.Value, id.Value, JsonHelper.Serialize(fileMsg), true)); } return(Json(new { Success = string.IsNullOrEmpty(msg.ToString()), Message = string.IsNullOrEmpty(msg.ToString()) ? "上传成功" : msg.ToString(), FileMsg = fileMsg.Count > 0 ? JsonHelper.Serialize(fileMsg) : string.Empty })); }
/// <summary> /// 提取图片 /// </summary> private List <ImagesDetailInfo> GetPicsFromExcel() { List <ImagesDetailInfo> result = new List <ImagesDetailInfo>(); try { var workBook = Globals.ThisAddIn.Application.ActiveWorkbook; var workSheet = (Worksheet)workBook.ActiveSheet; FileOperateHelper.DeleteFolder(savePathGetImage); if (!Directory.Exists(savePathGetImage)) { Directory.CreateDirectory(savePathGetImage); } for (int i = 1; i <= workSheet.Shapes.Count; i++) { var pic = workSheet.Shapes.Item(i); if (pic != null && pic.Type == Microsoft.Office.Core.MsoShapeType.msoPicture) { try { pic.Copy(); IDataObject ido = null; Dispatcher.Invoke(new System.Action(() => { try { ido = Clipboard.GetDataObject(); } catch { } })); if (ido != null && ido.GetDataPresent(DataFormats.Bitmap)) { System.Windows.Interop.InteropBitmap bmp = (System.Windows.Interop.InteropBitmap)ido.GetData(DataFormats.Bitmap); if (bmp != null) { if (!Directory.Exists(savePathGetImage)) { Directory.CreateDirectory(savePathGetImage); } Util.SaveImageToFile(bmp.Clone(), savePathGetImage + pic.Name + ".jpg"); result.Add(new ImagesDetailInfo() { ImgResultPath = savePathGetImage + pic.Name + ".jpg", UnCheckWordExcelRange = pic }); } } } catch (Exception ex) { CheckWordUtil.Log.TextLog.SaveError(ex.Message); } } } Dispatcher.Invoke(new System.Action(() => { System.Windows.Forms.Clipboard.Clear(); })); } catch (Exception ex) { CheckWordUtil.Log.TextLog.SaveError(ex.Message); } return(result); }
/// <summary> /// 提取图片 /// </summary> private List <ImagesDetailInfo> GetImagesFromWord() { List <ImagesDetailInfo> result = new List <ImagesDetailInfo>(); try { FileOperateHelper.DeleteFolder(savePathGetImage); if (!Directory.Exists(savePathGetImage)) { Directory.CreateDirectory(savePathGetImage); } object xx = null; bool hasPic = false; int index = 1; foreach (Microsoft.Office.Interop.Word.Paragraph paragraph in Application.ActiveDocument.Paragraphs) { foreach (InlineShape ils in paragraph.Range.InlineShapes) { if (ils != null) { if (ils.Type == WdInlineShapeType.wdInlineShapePicture) { //ils.Range.Copy(); //System.Drawing.Image image = null; //Dispatcher.Invoke(new Action(() => //{ // image = System.Windows.Forms.Clipboard.GetImage(); //})); //if (image != null) //{ // image.Save(savePathGetImage + "照片-" + index + ".jpg"); // result.Add(new ImagesDetailInfo() { ImgResultPath = savePathGetImage + "照片-" + index + ".jpg", UnCheckWordRange = ils.Range }); // index++; //} //Dispatcher.Invoke(new Action(() => //{ // System.Windows.Forms.Clipboard.Clear(); //})); try { if (!hasPic) { Dispatcher.Invoke(new System.Action(() => { if (Clipboard.ContainsText()) { xx = Clipboard.GetText(); } })); } } catch (Exception ex) { } hasPic = true; try { ils.Select(); IDataObject ido = null; Dispatcher.Invoke(new Action(() => { try { Application.Selection.CopyAsPicture(); ido = Clipboard.GetDataObject(); } catch { } })); if (ido != null && ido.GetDataPresent(DataFormats.Bitmap)) { System.Windows.Interop.InteropBitmap bmp = (System.Windows.Interop.InteropBitmap)ido.GetData(DataFormats.Bitmap); if (bmp != null) { if (!Directory.Exists(savePathGetImage)) { Directory.CreateDirectory(savePathGetImage); } Util.SaveImageToFile(bmp.Clone(), savePathGetImage + "照片-" + index + ".jpg"); result.Add(new ImagesDetailInfo() { ImgResultPath = savePathGetImage + "照片-" + index + ".jpg", UnCheckWordRange = ils.Range }); index++; } } } catch { } } } } } if (hasPic) { Dispatcher.BeginInvoke(new Action(() => { System.Windows.Forms.Clipboard.Clear(); if (xx != null) { try { System.Windows.Forms.Clipboard.SetDataObject(xx); } catch (Exception ex) { } } })); } } catch (Exception ex) { CheckWordUtil.Log.TextLog.SaveError(ex.Message); } return(result); }
public static void ModifyXcodeProject(List <ProjectItemInformation> items, string projectFilePath) { string projectSettingFileName = GetXcodeProjectFilePath(projectFilePath); FileStream stream = File.Open(projectSettingFileName, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); string content = reader.ReadToEnd(); reader.Close(); projectPath = projectFilePath; projectContent = content; targetName = DEPLOY_TARGET_NAME; buildPhaseDict.Clear(); InitializeConfigurationGuid(); foreach (ProjectItemInformation item in items) //(string fileName in files) { if (item is ProjectGroupInformation) { ProjectGroupInformation info = item as ProjectGroupInformation; string referenceGroupGuid = AddGroup(ref content, info); AddFileToGroup(ref content, info.ParentGroupName, referenceGroupGuid, info.GroupName); } else { ProjectFileInformation info = item as ProjectFileInformation; info.Initialize(); if (info is FrameworkFileInformation) { FrameworkFileInformation frameworkInfo = info as FrameworkFileInformation; if (frameworkInfo.FrameworkType == FrameworkType.Custom) { AddFrameworkConfiguration(ref content, frameworkInfo.FilePath); frameworkInfo.FilePath = frameworkInfo.FileName; } } if (info is ResourceFileInformation) { info.FilePath = FileOperateHelper.GetRelativePathFromAbsolutePath(projectPath, info.FilePath); } else if (info is SourceFileInformation) { info.FilePath = FileOperateHelper.GetRelativePathFromAbsolutePath(System.IO.Path.Combine(projectPath, "Classes"), info.FilePath); } string referenceFileGuid = AddFileReference(ref content, info); AddFileToGroup(ref content, info.ParentGroupName, referenceFileGuid, info.FileName); if (info.Phase != null) { string buildFileGuid = AddBuildFile(ref content, info, referenceFileGuid); AddBuildFileToPhase(ref content, buildFileGuid, info.FileName, info.Phase); } } } stream = File.Open(projectSettingFileName, FileMode.Create, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); writer.Write(content); writer.Close(); Debug.Log("Success!"); }