private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { var dlg = new OpenFileDialog { Filter = "JPEG 2000 files (*.jp2)|*.jp2", Multiselect = false, Title = "Select JPEG 2000 file" }; if (!dlg.ShowDialog(this).GetValueOrDefault()) return; using (var stream = dlg.OpenFile()) { var image = J2kImage.FromStream(stream).As<ImageSource>(); DecodedImage.Source = image; ImageName.Text = dlg.FileName; } }
public static string getStringFromFile() { string result = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); if ((bool)openFileDialog.ShowDialog()) { System.IO.Stream fileStream = openFileDialog.OpenFile(); textFilePath = openFileDialog.FileName.Replace(openFileDialog.SafeFileName, ""); using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream)) { while (!reader.EndOfStream) result += (char)reader.Read(); } fileStream.Close(); } return result; }
private void LoadLibButton_Click(object sender, RoutedEventArgs e) { Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "Dynamically Linked Library|*.dll"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == true) { try { if ((myStream = openFileDialog1.OpenFile()) != null) { using (myStream) { LibraryPath = openFileDialog1.FileName; } } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }
private void ButtonBase_OnClick (object sender, RoutedEventArgs e) { try { var dig = new OpenFileDialog(); dig.Title = "选择文件"; dig.Filter = "rtf文件|*.rtf"; dig.RestoreDirectory = true; if(dig.ShowDialog() == true) { using(var ms = dig.OpenFile()) { var bytes = new byte[ms.Length]; ms.Read(bytes, 0, (int)ms.Length); var str = Encoding.UTF8.GetString(bytes); this.RtfText = str; } } } catch(Exception c) { MessageBox.Show(c.Message); } }
private RadDocument LoadDocumentToInsert() { RadDocument document = null; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Word Documents (*.docx)|*.docx|All Files (*.*)|*.*"; if (ofd.ShowDialog() == true) { string extension; #if SILVERLIGHT extension = ofd.File.Extension.ToLower(); #else extension = Path.GetExtension(ofd.SafeFileName).ToLower(); #endif IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension); Stream stream; #if SILVERLIGHT stream = ofd.File.OpenRead(); #else stream = ofd.OpenFile(); #endif using (stream) { document = provider.Import(stream); } } return document; }
private void ImportDB_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.DefaultExt = ".db"; dialog.Filter = "DataBase(.db)|*.db"; bool? res = dialog.ShowDialog(); if (res.HasValue && res.Value) { DBConnection.ins().closeDb(); Stream stream = dialog.OpenFile(); FileStream fs = new FileStream(DBConnection.path, FileMode.OpenOrCreate); byte[] buffer = new byte[1024]; int count = 0; while ((count = stream.Read(buffer, 0, 1024)) > 0) { fs.Write(buffer, 0, count); } stream.Close(); fs.Close(); MessageBoxResult result = MessageBox.Show("匯入資料庫需重開系統", "確認視窗", MessageBoxButton.OK, MessageBoxImage.Information); if (result == MessageBoxResult.OK) { System.Diagnostics.Process.Start(System.Windows.Application.ResourceAssembly.Location); System.Windows.Application.Current.Shutdown(); } } }
private void SelectFileButton_Click(object sender, RoutedEventArgs e) { // TODO 1 open file dialog and choose directoy to start OpenFileDialog dialog = new OpenFileDialog(); dialog.InitialDirectory = "C:\\Users\\Jason\\Downloads"; if (dialog.ShowDialog() == true) { try { using (StreamReader reader = new StreamReader(dialog.OpenFile())) { string line; StringBuilder sb = new StringBuilder(); while ((line = reader.ReadLine()) != null) { sb.Append(line).Append("...").Append(Environment.NewLine); } ContentTb.Text = sb.ToString(); } } catch (IOException ex) { StatusLb.Content = ex.Message; } } // TODO 2 if the user selected a file display file/dir name and text }
public static string ReadFile(this SerialPort com) { Stream input = null; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Environment.CurrentDirectory; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == true) { try { if ((input = openFileDialog.OpenFile()) != null) using (StreamReader sr = new StreamReader(input)) { string text = sr.ReadToEnd(); byte [] buffer = ASCIIEncoding.ASCII.GetBytes(text); com.Write(buffer, 0, buffer.Length); return string.Format("File {0}: \n{1}\n", openFileDialog.FileName, text); } } catch (Exception ex) { return "Error: Could not read file from disk. Original error: " + ex.Message; } } return "File isn`t selected.\n"; }
/// <summary> /// 图片上传 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnImage_Click(object sender, RoutedEventArgs e) { //创建"打开文件"对话框 Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); //设置文件类型过滤 dlg.Filter = "图片|*.jpg;*.png;*.gif;*.bmp;*.jpeg"; // 调用ShowDialog方法显示"打开文件"对话框 Nullable <bool> result = dlg.ShowDialog(); if (result == true) { Stream phop; int length = 0; ////获取所选文件名并在FileNameTextBox中显示完整路径 //string filename = dlg.FileName; //Model.Tumodel.IcoImage = filename; //Model.ImgPath = filename; //将选择的文件上传本项目特定的文件目录下 phop = dlg.OpenFile(); if (phop != null) { length = (int)phop.Length; byte[] bytes = new byte[length]; phop.Read(bytes, 0, length); //todo 判断以前是否有图片有的话直接替换不生成一个新的图片 var reslt = CreateImageByPath(bytes, "Image"); if (reslt != "") { Model.Tumodel.IcoImage = reslt; } } } }
public override InteriorField[,] GetLayout() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.DefaultExt = "txt"; DirectoryInfo currentDir = new DirectoryInfo(Environment.CurrentDirectory); openFileDialog.InitialDirectory = (currentDir.EnumerateDirectories().FirstOrDefault(d => d.Name == DataSubdirName) ?? currentDir).FullName; if (openFileDialog.ShowDialog().GetValueOrDefault()) { this.LayoutIdentifier = openFileDialog.FileName; using (StreamReader readLines = new StreamReader(openFileDialog.OpenFile())) { List<List<InteriorField>> layout = readLines .ReadToEnd() .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s .Select(c => this.CreateField(c)).ToList()).ToList(); int columnsCount = layout.Max(l => l.Count); InteriorField[,] result = new InteriorField[layout.Count, columnsCount]; for (int row = 0; row < layout.Count; row++) { for (int col = 0; col < layout[row].Count; col++) { result[row, col] = layout[row][col]; } } return result; } } else { return null; } }
private void chooseFileToolStripMenuItem_Click(object sender, EventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = "Document"; // Default file name dlg.DefaultExt = ".txt"; // Default file extension dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension var userList = new List <User>(); Nullable <bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document string filename = dlg.FileName; var fileStream = dlg.OpenFile(); using (StreamReader reader = new StreamReader(fileStream)) { string line; while ((line = reader.ReadLine()) != null) { User user = new User(line); boxen.Items.Add(user); count++; } } } numberOfItems_Updater(); //Read the contents of the file into a stream }
private void bouttonEnregistrerSous_Click(object sender, RoutedEventArgs e) { if (CheminCompletNomFichier.Equals("")) { EnregistrerNouveauFichier(); } else { SaveFileDialog saveFileDialog1 = new SaveFileDialog { Filter = "txt files (*.txt)|*.txt", Title = "Enregistrer votre fichier" }; try { if (saveFileDialog1.ShowDialog() == true) { File.Copy(CheminCompletNomFichier, saveFileDialog1.FileName); //Ouvrir le nouveau fichier créer try { nomFichier = LireNomFichier(saveFileDialog1.FileName); if (!nomFichier.Equals("")) { Microsoft.Win32.OpenFileDialog d = new Microsoft.Win32.OpenFileDialog(); d.FileName = saveFileDialog1.FileName; Stream myStream = d.OpenFile(); if (myStream != null) { using (myStream) { using (StreamReader reader = new StreamReader(myStream, Encoding.UTF8)) { editeur.Text = reader.ReadToEnd(); ExtensionFichier = LireExtensionFichier(d.FileName); this.Title = "Editeur Fichier : " + d.FileName + " | " + ExtensionFichier; CheminCompletNomFichier = d.FileName; this.FontSize = 14; } } } } else { MessageBox.Show("Le fichier n'existe pas."); } } catch (Exception ee) { MessageBox.Show("Une erreur est survenue lors de l'ouverture du fichier : '" + ee.Message + "' "); } } } catch (Exception eee) { MessageBox.Show("Erreur lors de l'enregistrement du fichier : '" + eee.Message + "'"); } } }
public Stream OpenFile(string defaultExtension, string filter) { var fd = new OpenFileDialog { DefaultExt = defaultExtension, Filter = filter }; var result = fd.ShowDialog(); return result != null && result.Value ? fd.OpenFile() : null; }
public string OpenBrowserDialog(string defaultPath) { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = defaultPath; ofd.OpenFile(); return ofd.FileName; }
/// <summary> /// /// </summary> /// <returns></returns> public Stream openfile() { var dialog = new OpenFileDialog(); if (dialog.ShowDialog() == true) { return dialog.OpenFile(); } return null; }
private void ChooseButton_OnClick(object sender, RoutedEventArgs e) { var dlg = new OpenFileDialog(); dlg.Filter = "(*.bmp, *.jpg, *.png)|*.bmp;*.jpg;*.png"; if (dlg.ShowDialog() == true) { this.ViewModel.BinaryData = dlg.OpenFile().ToArray(); } }
public void SelectImage() { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = "Image Files|*.jpeg;*.jpg;*.png;*.gif"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { EquipmentImage = ImageHandler.ConvertToByteArray(dlg.OpenFile()); RaisePropertyChanged("EquipmentImage"); } }
private void ChangeStyleCommand_Executed(object sender, ExecutedRoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "XAML Styles (*.xaml)|*.xaml"; dlg.InitialDirectory = Environment.CurrentDirectory; if (dlg.ShowDialog().Value) { using (Stream fs = dlg.OpenFile()) { LoadStyle(fs); } } }
private void LoadASM(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.FileName = ""; dialog.DefaultExt = ".asm"; dialog.Filter = "Assembly (.asm)|*.asm|Text Files (.txt)|*.txt"; bool? res = dialog.ShowDialog(); if(res == true) { StreamReader f = new StreamReader(dialog.OpenFile()); Assembly.Text = f.ReadToEnd(); f.Close(); } }
public static void Open(string filePath, ref ObservableCollection<Achievement> achievements) { var openDialog = new OpenFileDialog {Filter = "Data files (*.save)|*.save;"}; var ok = openDialog.ShowDialog(); if (!ok.Value) return; _currentFilePath = openDialog.FileName; using (var fs = openDialog.OpenFile()) { var serializer = new XmlSerializer(typeof(ObservableCollection<Achievement>)); achievements = (ObservableCollection<Achievement>)serializer.Deserialize(fs); } }
private void uploadBtn_Click(object sender, RoutedEventArgs e) { var fileDlg = new OpenFileDialog(); if (fileDlg.ShowDialog() == true) { new FileInfo(fileDlg.FileName); using (Stream s = fileDlg.OpenFile()) { attachTxtBox.Text = fileDlg.FileName; } } }
public bool OpenDocument() { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == true) { _currentFile = dlg.FileName; using (Stream stream = dlg.OpenFile()) { TextRange range = new TextRange(_textBox.Document.ContentStart, _textBox.Document.ContentEnd); range.Load(stream, DataFormats.Rtf); } return true; } return false; }
// return a read-only stream public static Stream Open() { OpenFileDialog fd = new OpenFileDialog(); // initial directory fd.InitialDirectory = Path.GetFullPath(initialDirectory); // allowed file types fd.Filter = filter; fd.RestoreDirectory = false; // select .xml as default fd.FilterIndex = 1; fd.Title = "Select Project Data File.."; if (fd.ShowDialog().GetValueOrDefault()) return fd.OpenFile(); else return null; }
private void LoadStyleSheet_Click(object sender, RadRoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Xaml Files|*.xaml"; if (ofd.ShowDialog() == true) { #if WPF using (var stream = ofd.OpenFile()) #else using (var stream = ofd.File.OpenRead()) #endif { Stylesheet stylesheet = XamlFormatProvider.LoadStylesheet(stream); stylesheet.ApplyStylesheetToDocument(this.editor.Document); } } }
private static Stream GetFileDialog(string suffix) { Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog { //InitialDirectory = Environment.CurrentDirectory, Filter = $"{char.ToUpper(suffix[0]) + suffix.Substring(1)} files (*.{suffix})|*.{suffix}|All files (*.*)|*.*", FilterIndex = 1, RestoreDirectory = true }; if ((bool)openFileDialog.ShowDialog()) { //Read the contents of the file into a stream return(openFileDialog.OpenFile()); } return(null); }
/// <summary> /// Ouvrir le fichier après la sélection par l'utilisateur /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BoutonOuvrir_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog { //InitialDirectory = "c:\\", Filter = "txt files (*.txt)|*.txt", FilterIndex = 2, RestoreDirectory = true, FileName = "Nom Fichier", DefaultExt = ".txt" }; if (dlg.ShowDialog() == true) { try { nomFichier = LireNomFichier(dlg.FileName); if (!nomFichier.Equals("")) { Stream myStream = dlg.OpenFile(); if (myStream != null) { using (myStream) { using (StreamReader reader = new StreamReader(myStream, Encoding.UTF8)) { editeur.Text = reader.ReadToEnd(); ExtensionFichier = LireExtensionFichier(dlg.FileName); this.Title = "Editeur Fichier : " + dlg.FileName + " | " + ExtensionFichier; CheminCompletNomFichier = dlg.FileName; this.FontSize = 14; } } } } else { MessageBox.Show("Le fichier n'existe pas."); } } catch (Exception ee) { MessageBox.Show("Une erreur est survenue lors de l'ouverture du fichier : '" + ee.Message + "' "); } } }
private void BrowsePicture_Click(object sender, RoutedEventArgs e) { if (ViewModel == null) return; Stream picture; var fileDialog = new OpenFileDialog(); fileDialog.InitialDirectory = "C:\\"; fileDialog.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg"; fileDialog.FilterIndex = 3; if (fileDialog.ShowDialog() ?? false) { try { if ((picture = fileDialog.OpenFile()) != null) { using (picture) { var folder = @"C:\Temp\Commander\Images\"; if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); var url = folder + System.IO.Path.GetFileName(fileDialog.FileName); using (var file = File.Create(url)) { picture.CopyTo(file); } ViewModel.Picture = url; } } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }
private void buttonOpenFile_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*"; bool? userClickedOK = dialog.ShowDialog(); directoryPath = dialog.FileName; if (userClickedOK == true) { Stream fileStream = dialog.OpenFile(); using (StreamReader reader = new StreamReader(fileStream)) { textBox.Text = reader.ReadToEnd(); } fileStream.Close(); textChanged = false; } }
private void ButtonOpenClick(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Zip File | *.zip"; bool? dialogResult = dialog.ShowDialog(); if (dialogResult == true) { #if WPF Stream stream = dialog.OpenFile(); #else Stream stream = dialog.File.OpenRead(); #endif using (ZipArchive zipArchive = new ZipArchive(stream)) { OpenedFileList.ItemsSource = zipArchive.Entries; } } }
private void Button_Click_2(object sender, RoutedEventArgs e) { OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog(); openFileDlg.FilterIndex = 1; openFileDlg.RestoreDirectory = true; Nullable <bool> result = openFileDlg.ShowDialog(); if (result == true) { txt_ruta.Text = openFileDlg.FileName; //Byte[] FotoBoleta = null; Stream myStream = openFileDlg.OpenFile(); FotoBoleta = Encrypt.StreamToByte(myStream); } }
private void LoadFile(object sender, RoutedEventArgs args) { var openFile = new OpenFileDialog { Filter = "FlowDocument Files (*.xaml)|*.xaml|All Files (*.*)|*.*", InitialDirectory = "Content" }; if (openFile.ShowDialog().HasValue) { var xamlFile = openFile.OpenFile() as FileStream; if (xamlFile == null) return; FlowDocument content = null; try { content = XamlReader.Load(xamlFile) as FlowDocument; if (content == null) throw (new XamlParseException("The specified file could not be loaded as a FlowDocument.")); } catch (XamlParseException e) { var error = "There was a problem parsing the specified file:\n\n"; error += openFile.FileName; error += "\n\nException details:\n\n"; error += e.Message; MessageBox.Show(error); return; } catch (Exception e) { var error = "There was a problem loading the specified file:\n\n"; error += openFile.FileName; error += "\n\nException details:\n\n"; error += e.Message; MessageBox.Show(error); return; } // At this point, there is a non-null FlowDocument loaded into content. FlowDocRdr.Document = content; } }
public Window2() { Log.writeToLog("Starting FileConverter " + Utilities.getVersionNumber()); Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Title = "Open Header file for conversion..."; dlg.DefaultExt = ".hdr"; // Default file extension dlg.Filter = "HDR Files (.hdr)|*.hdr"; // Filter files by extension Nullable<bool> result = dlg.ShowDialog(); if (result == null || result == false) { this.Close(); Environment.Exit(0); } directory = System.IO.Path.GetDirectoryName(dlg.FileName); head = (new HeaderFileReader(dlg.OpenFile())).read(); ED = head.Events; bdf = new BDFEDFFileReader( new FileStream(System.IO.Path.Combine(directory, head.BDFFile), FileMode.Open, FileAccess.Read)); oldSR = bdf.NSamp / bdf.RecordDurationDouble; oldNP = bdf.NSamp; oldNS = bdf.RecordDurationDouble; InitializeComponent(); this.MinHeight = SystemInformation.WorkingArea.Height - 240; this.Title = "Convert " + System.IO.Path.GetFileNameWithoutExtension(dlg.FileName); this.TitleLine.Text = head.Title + " - " + head.Date + " " + head.Time + " S=" + head.Subject.ToString("0000"); _EDEList = ED.Values.ToList<EventDictionaryEntry>(); listView1.SelectedItem = 0; listView1.Focus(); listView1.ItemsSource = EDEList; System.Windows.Data.Binding GVBinding = new System.Windows.Data.Binding(); GVBinding.Source = this; GVBinding.NotifyOnSourceUpdated = true; GVBinding.Path = new PropertyPath("GVList"); GVBinding.Mode = BindingMode.OneWay; listView2.SetBinding(System.Windows.Controls.ListView.ItemsSourceProperty, GVBinding); GVList = EDEList[0].GroupVars; }
private void OpenFile_Click(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog { Multiselect = false, Filter = "Pascal/Delphi code (*.pas, *.dpr)|*.pas;*.dpr|All files (*.*)|*.*", FilterIndex = 1, InitialDirectory = @"E:\Programs\VS\_MSiSvInfT\Laba1\", Title = "Open code" }; if (ofd.ShowDialog(WMain) != true) return; TbFilePath.Text = ofd.FileNames[0]; var sourceStream = new StreamReader(ofd.OpenFile(),Encoding.Default); TbFileText.Text = sourceStream.ReadToEnd(); sourceStream.Close(); }
private void OpenButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofg = new OpenFileDialog(); ofg.Title = "Select an image"; ofg.Filter = "Images (.jpg, .png, .gif, .bmp)|*.jpg;*.png;*.gif;*.bmp"; ofg.Multiselect = false; if (ofg.ShowDialog() == true) { if (ofg.FileName != null && ofg.FileName.Length > 0) { ofg.OpenFile(); FileStream fs = new FileStream(ofg.FileName, FileMode.Open, FileAccess.Read); TextBox.Text = ByteImageConverter.ImageToByte(fs); byte[] imgStr = Convert.FromBase64String(TextBox.Text); Image.Source = ByteImageConverter.ByteToImage(imgStr); } } }
// Load File Dialog private void mnu_LOAD(object sender, RoutedEventArgs e) { //configure save file dialog box Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = "config"; //default file name dlg.DefaultExt = ".xml"; //default file extension dlg.Filter = "XML documents (.xml)|*.xml"; //filter files by extension // Show save file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { Stream load_stream = dlg.OpenFile(); RSS_LogicEngine.Component_View component_view; component_view = RSS_LogicEngine.Component_View.Get_Instance(); component_view.Load_Components(load_stream); load_stream.Close(); } }
private void Load(object sender, RoutedEventArgs e) { _dlxMatrix.Reset(); var ofd = new OpenFileDialog(); ofd.InitialDirectory = "C:\\Sudoku\\"; if (ofd.ShowDialog() == true) { using (var stream = ofd.OpenFile()) { using (var reader = new StreamReader(stream)) { _dlxMatrix.Load(reader); } } //using (FileStream Stream = File.Open(Path, FileMode.Open)) { } } }
//Image envent protected void Button_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Multiselect = false; open.Filter = "AllFiles|*.*"; if ((bool)open.ShowDialog()) { //SetLogo(sender, new DataEventArgs<Stream>(open.OpenFile())); //txtLogo.Text = open.FileName; this.StreamFile = open.OpenFile(); this.FileName = open.FileName; this.txtLogo.Text = open.FileName; EventHandler temp = OnFileUpload; if (temp != null) temp(sender, e); } }
void LoadPdf(object sender, EventArgs args) { var dialog = new OpenFileDialog { Filter = "PDF files|*.pdf" }; if (dialog.ShowDialog() == true) { using (var fileStream = dialog.OpenFile()) { try { pdfViewer.LoadDocument(fileStream); } catch (Exception ex) { MessageBox.Show("Could not load PDF file"); } } } }
private void button_Image_Click(object sender, RoutedEventArgs e) { Stream checkStream = null; Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Multiselect = false; openFileDialog.Filter = "تصاویر|*.bmp;*.jpg;*.png"; if ((bool)openFileDialog.ShowDialog()) { try { if ((checkStream = openFileDialog.OpenFile()) != null) { ImagePath = openFileDialog.FileName; Image_Profile.Source = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.RelativeOrAbsolute)); } } catch { MessageBox.Show("خطا: فایل ارسال شده قابل خواندن نیست"); } } }
/// <summary> /// 上传一个文档 /// </summary> /// <param name="siteUrl">指定站点</param> /// <param name="documentListName">指定文件夹名称</param> /// <returns>返回操作提示</returns> public Microsoft.SharePoint.Client.File UploadFileToDocumntLibrary(string siteUrl, string folderName) { Microsoft.SharePoint.Client.File uploadFile = null; try { if (clientContext != null) { //使用打开对话框 Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog(); //声明一个缓冲区 byte[] documentStream = null; //文件名称 string documentName = null; //点击确定 if (dialog.ShowDialog() == true) { //获取指定名称 documentName = dialog.SafeFileName; //获取文件流 Stream stream = dialog.OpenFile(); //创建一个缓冲区 documentStream = new byte[stream.Length]; //将流写入指定缓冲区 stream.Read(documentStream, 0, documentStream.Length); //上传文档 using (clientContext) { //设置默认凭据 //通过标题获取文档库 Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(folderName); //加载并更新列表 LoadMethod(documentsList); // LoadMethod(documentsList.RootFolder); //获取文档库url var d = documentsList.RootFolder.ServerRelativeUrl; string a = d.Replace(documentsList.ParentWebUrl + "/", ""); //新建一个文件信息类 var fileCreationInformation = new FileCreationInformation(); //设置文件内容 fileCreationInformation.Content = documentStream; //可以覆盖 fileCreationInformation.Overwrite = true; //文件信息的uri fileCreationInformation.Url = siteUrl + "/" + a + "/" + documentName; //加载文档 uploadFile = documentsList.RootFolder.Files.Add(fileCreationInformation); //加载并更新文件 LoadMethod(uploadFile); stream.Dispose(); stream.Close(); } } else { return(null); } } } catch (Exception ex) { MethodLb.CreateLog(this.GetType().FullName, "UploadFileToDocumntLibrary", ex.ToString(), siteUrl, folderName); } finally { } return(uploadFile); }
private void btnOpenFile_Click(object sender, RoutedEventArgs e) { Stream myStream = null; // opens excel File Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); //openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); openFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*"; openFileDialog.RestoreDirectory = false; if (openFileDialog.ShowDialog() == true) { var a = new Microsoft.Office.Interop.Excel.Application(); try { if ((myStream = openFileDialog.OpenFile()) != null) { using (myStream) { // creates a new Workbook using the selected Excel File Workbook w = a.Workbooks.Open(openFileDialog.FileName); // gets the root path of the excel File string directoryPath = Path.GetDirectoryName(openFileDialog.FileName); foreach (Worksheet ws in w.Sheets) { string range = ws.PageSetup.PrintArea; ws.Protect(Contents: false); // TODO: Find the first-non blank cell in each sheet to avoid hardcoding // Gets current range Range r = ws.get_Range("B2", System.Type.Missing).CurrentRegion; // Copies the selected range in clipboard as an image r.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap); // saves the Image and displays output Bitmap image = new Bitmap(System.Windows.Forms.Clipboard.GetImage()); string BMPName = ws.Name; string imgPath = $@"{directoryPath}\{BMPName}.bmp"; txtEditor.Text += $"Saving sheet {BMPName} in {imgPath}...\n"; if (File.Exists(imgPath)) { txtEditor.Text += $"File already exists!. Deleting file...\n"; File.Delete(imgPath); } image.Save(imgPath); txtEditor.Text += "Done.\n\n"; } //Worksheet ws = w.Sheets["DIA-3"]; a.DisplayAlerts = false; // System.Runtime.InteropServices.COMException Excepción de HRESULT: 0x80010105 (RPC_E_SERVERFAULT) //ChartObject chartObj = ws.ChartObjects().Add(r.Left, r.Top, r.Width, r.Height); //chartObj.Activate(); //Chart chart = chartObj.Chart; //chart.Paste(); //chart.Export(@"C:\Dev\Excel2BMP\Excel2BMP\resources\image.JPG", "JPG"); //chartObj.Delete(); w.Close(SaveChanges: false); } } } catch (Exception ex) { System.Windows.MessageBox.Show("Error: Could not read file: " + ex.Message); } finally { a.Quit(); } } }
public Stream OpenFile() { return(mInnerDialog.OpenFile()); }