public static bool GetCsvFileContents(ref string sChosenFile, ref string sCsvFileContents) { bool bRet = false; string sFolderPath = GetPathToAdditionalPropertiesFolder(); sCsvFileContents = string.Empty; System.Windows.Forms.OpenFileDialog oFD = new System.Windows.Forms.OpenFileDialog(); string sFile = string.Empty; string sPath = (Path.GetDirectoryName(sChosenFile)); if (UserIoHelper.PickLoadFromFile(sPath, "*.csv", ref sFile, "CSV files (*.csv)|*.csv")) { try { sChosenFile = sFile; sCsvFileContents = System.IO.File.ReadAllText(sFile); bRet = true; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error loading file.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } return(bRet); }
/// <summary> /// this button handles displaying the File Open dialog and loading the settings from an existing xml file /// useriohelper is for displaying the dialog and serialhelper is for parsing out the xml for settings /// once the settings have been parsed from the xml file, setformfromconnectionsettings is called to populate the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mnuFileLoadSettings_Click(object sender, EventArgs e) { string sFile = string.Empty; string sFilter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; string sConnectionSettings = string.Empty; ConnectionSettings oConnectionSetting = null; string sFileContents = string.Empty; if (UserIoHelper.PickLoadFromFile(AppDomain.CurrentDomain.BaseDirectory, "*.xml", ref sFile, sFilter)) { try { sFileContents = System.IO.File.ReadAllText(sFile); oConnectionSetting = SerialHelper.DeserializeObjectFromString <ConnectionSettings>(sFileContents); if (oConnectionSetting == null) { throw new Exception("Settings file cannot be deserialized."); } SetFormFromConnectionSettings(oConnectionSetting); } catch (Exception ex) { txtBoxErrorLog.Clear(); txtBoxErrorLog.Text = ex.ToString() + "Error Loading File"; } } oConnectionSetting = null; }
public bool LoadSettingFromFile() //ref TestingForm oTestingForm) { bool bRet = false; string sFile = string.Empty; string sConnectionSettings = string.Empty; //TestSettingsData oTestSettingsData = null; this.ClearSettings(); string sFileContents = string.Empty; if (UserIoHelper.PickLoadFromFile(FormDataFilePath, "*.xml", ref sFile, "XML files (*.xml)|*.xml")) { try { sFileContents = System.IO.File.ReadAllText(sFile); SettingsData = SerialHelper.DeserializeObjectFromString <TestSettingsData>(sFileContents); //SetFormFromData(ref oTestingForm); bRet = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Saving File"); } } //oTestSettingsData = null; return(bRet); }
private void btnBrowseForFile_Click(object sender, EventArgs e) { string sSelectedFile = string.Empty; if (UserIoHelper.PickLoadFromFile(Application.UserAppDataPath, "*.png", ref sSelectedFile, "All files (*.*)|*.*")) { this.txtFile.Text = sSelectedFile; } ; }
private void btnInstallApp_Click(object sender, EventArgs e) { string sSelectedFile = string.Empty; if (UserIoHelper.PickLoadFromFile(Application.UserAppDataPath, "*.*", ref sSelectedFile, "All files (*.*)|*.*")) { byte[] baContents = System.IO.File.ReadAllBytes(sSelectedFile); System.IO.MemoryStream oStream = new System.IO.MemoryStream(baContents); _CurrentService.InstallApp(oStream); } ; }
private void btnLoadFileSelect_Click(object sender, EventArgs e) { string sContent = string.Empty; string sSuggestedFilename = "*.*"; string sSelectedfile = string.Empty; string sFilter = "Jpg files (*.jpg)|*.jpg|XML files (*.xml)|*.xml|All files (*.*)|*.*"; if (UserIoHelper.PickLoadFromFile(txtLoadFile.Text.Trim(), sSuggestedFilename, ref sSelectedfile, sFilter)) { txtLoadFile.Text = sSelectedfile; } }
private void btnLoadExample_Click(object sender, EventArgs e) { string sInitialDirectory = Application.StartupPath + "\\HtmlBodyExamples"; string sSuggestedFilename = "*.*"; string sSelectedfile = string.Empty; string sFilter = "HTM files (*.htm)|*.htm|HTML files (*.html)|*.html|TXT files (*.txt)|*.txt|All files (*.*)|*.*"; if (UserIoHelper.PickLoadFromFile(sInitialDirectory, sSuggestedFilename, ref sSelectedfile, sFilter)) { try { txtBody.Text = System.IO.File.ReadAllText(sSelectedfile); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error reading file."); } } }
private void BtnLoadCertificate_Click(object sender, EventArgs e) { string sFile = string.Empty; string sConnectionSettings = string.Empty; // PostFormSetting oPostFormSetting = null; string sFileContents = string.Empty; if (UserIoHelper.PickLoadFromFile(Application.UserAppDataPath, "*.cer", ref sFile, "CER files (*.cer)|*.cer")) { try { txtAuthCertificatePath.Text = sFile; if (!System.IO.File.Exists(sFile)) { MessageBox.Show("File does not exist."); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error Loading File"); } } }