public static byte[] GetBytes(this IFileData fileData) { var memoryStream = new MemoryStream(); fileData?.SaveToStream(memoryStream); return(memoryStream.ToArray()); }
protected override void ReadViewModeValueCore() { IFileData fileData = PropertyValue as IFileData; if (fileData != null && fileData.FileName.ToLower().Contains(".pdf")) { using (MemoryStream stream = new MemoryStream()) { fileData.SaveToStream(stream); //LoadDocument(stream); DocumentProcessor.LoadDocument(stream, true); BindDataView(); } } }
public void Save(IFileData fileData) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.CreatePrompt = false; saveFileDialog.OverwritePrompt = true; string text = Path.GetExtension(fileData.FileName).TrimStart(new char[] { '.' }); string localizedText = CaptionHelper.GetLocalizedText("FileAttachments", "WordAll"); string localizedText2 = CaptionHelper.GetLocalizedText("FileAttachments", "WordFiles"); saveFileDialog.Filter = string.Concat(new string[] { text.ToUpper(), " ", localizedText2, " (*.", text, ")|*.", text, "|", localizedText, " ", localizedText2, " (*.*)|*.*" }); //IModelOptionsFileAttachments modelOptionsFileAttachments = base.Application.Model.Options as IModelOptionsFileAttachments; //saveFileDialog.InitialDirectory = modelOptionsFileAttachments.Attachments.DefaultDirectory; saveFileDialog.FileName = fileData.FileName; saveFileDialog.Title = CaptionHelper.GetLocalizedText("FileAttachments", "OverwritePromptCaption"); if (saveFileDialog.ShowDialog(Form.ActiveForm) == DialogResult.OK) { //modelOptionsFileAttachments.Attachments.DefaultDirectory = Path.GetDirectoryName(saveFileDialog.FileName); using (FileStream fileStream = new FileStream(saveFileDialog.FileName, FileMode.Create)) { fileData.SaveToStream(fileStream); } } } }
public void Open(IFileData fileData) { DevExpress.ExpressApp.Utils.Guard.ArgumentNotNull(fileData, "fileData"); if (!FileDataHelper.IsFileDataEmpty(fileData)) { CustomFileOperationEventArgs customFileOperationEventArgs = new CustomFileOperationEventArgs(fileData); this.OnCustomOpenFileWithDefaultProgram(customFileOperationEventArgs); if (!customFileOperationEventArgs.Handled) { string text = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("B")); try { Directory.CreateDirectory(text); } catch { Tracing.Tracer.LogValue("tempDirectory", text); throw; } string text2 = Path.Combine(text, fileData.FileName); try { using (FileStream fileStream = new FileStream(text2, FileMode.CreateNew)) { fileData.SaveToStream(fileStream); } Process.Start(text2); } catch { Tracing.Tracer.LogValue("tempFileName", text2); throw; } } } }
public void Save(IFileData fileData) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.CreatePrompt = false; saveFileDialog.OverwritePrompt = true; string text = Path.GetExtension(fileData.FileName).TrimStart(new char[] { '.' }); string localizedText = CaptionHelper.GetLocalizedText("FileAttachments", "WordAll"); string localizedText2 = CaptionHelper.GetLocalizedText("FileAttachments", "WordFiles"); saveFileDialog.Filter = string.Concat(new string[] { text.ToUpper(), " ", localizedText2, " (*.", text, ")|*.", text, "|", localizedText, " ", localizedText2, " (*.*)|*.*" }); //IModelOptionsFileAttachments modelOptionsFileAttachments = base.Application.Model.Options as IModelOptionsFileAttachments; //saveFileDialog.InitialDirectory = modelOptionsFileAttachments.Attachments.DefaultDirectory; saveFileDialog.FileName = fileData.FileName; saveFileDialog.Title = CaptionHelper.GetLocalizedText("FileAttachments", "OverwritePromptCaption"); if (saveFileDialog.ShowDialog(Form.ActiveForm) == DialogResult.OK) { //modelOptionsFileAttachments.Attachments.DefaultDirectory = Path.GetDirectoryName(saveFileDialog.FileName); using (FileStream fileStream = new FileStream(saveFileDialog.FileName, FileMode.Create)) { fileData.SaveToStream(fileStream); } } } }
public void Open(IFileData fileData) { DevExpress.ExpressApp.Utils.Guard.ArgumentNotNull(fileData, "fileData"); if (!FileDataHelper.IsFileDataEmpty(fileData)) { CustomFileOperationEventArgs customFileOperationEventArgs = new CustomFileOperationEventArgs(fileData); this.OnCustomOpenFileWithDefaultProgram(customFileOperationEventArgs); if (!customFileOperationEventArgs.Handled) { string text = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("B")); try { Directory.CreateDirectory(text); } catch { Tracing.Tracer.LogValue("tempDirectory", text); throw; } string text2 = Path.Combine(text, fileData.FileName); try { using (FileStream fileStream = new FileStream(text2, FileMode.CreateNew)) { fileData.SaveToStream(fileStream); } Process.Start(text2); } catch { Tracing.Tracer.LogValue("tempFileName", text2); throw; } } } }
private bool OpenFile(IModuleExchange parent, IFileData fileData, Guid contextID, XafApplication app) { bool result = false; switch (System.IO.Path.GetExtension(fileData.FileName)) { case ".eeg": { result = true; string tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("B")); System.IO.Directory.CreateDirectory(tempDirectory); string tempFileName = Path.Combine(tempDirectory, fileData.FileName); try { using (FileStream stream = new FileStream(tempFileName, FileMode.CreateNew)) { fileData.SaveToStream(stream); } RegistryKey key = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, ""); RegistryKey target_key = key.OpenSubKey(keyPath); if (target_key != null ? target_key.GetValueNames().Contains(keyName) : false) { String path = Convert.ToString(target_key.GetValue(keyName)) + appName; Process process = new Process(); ProcessStartInfo ps = new ProcessStartInfo(path); ps.Arguments = String.Format(@"""{0}""", tempFileName); process.StartInfo = ps; process.Exited += (object sender, EventArgs args) => { parent.ProcessMessage(contextID, "Stop"); }; process.Start(); process.EnableRaisingEvents = true; } } catch { Tracing.Tracer.LogValue("tempFileName", tempFileName); throw; } } break; case ".mef": { result = true; string tempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("B")); System.IO.Directory.CreateDirectory(tempDirectory); string tempFileName = Path.Combine(tempDirectory, fileData.FileName); try { using (FileStream stream = new FileStream(tempFileName, FileMode.CreateNew)) { fileData.SaveToStream(stream); } RegistryKey key = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, ""); RegistryKey target_key = key.OpenSubKey(keyPath); if (target_key != null ? target_key.GetValueNames().Contains("MainEegPath") : false) { String path = Convert.ToString(target_key.GetValue("MainEegPath")) + "eeg.exe"; Process process = new Process(); ProcessStartInfo ps = new ProcessStartInfo(path); ps.Arguments = String.Format(@"""{0}""", tempFileName); process.StartInfo = ps; process.Exited += (object sender, EventArgs args) => { parent.ProcessMessage(contextID, "Stop"); }; process.Start(); process.EnableRaisingEvents = true; } } catch { Tracing.Tracer.LogValue("tempFileName", tempFileName); throw; } } break; } return result; }