private void button1_Click(object sender, EventArgs e) { const string sPath = @"C:\Testing\Save.text"; System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath); SaveFile.Write("Func1, Func2, Func3"); SaveFile.WriteLine(" "); foreach (var item in listBox1.Items) { SaveFile.Write("f1 "); // SaveFile.Write(" , "); SaveFile.WriteLine(item.ToString()); } foreach (var item in listBox2.Items) { SaveFile.Write("f2 "); // SaveFile.Write(" , "); SaveFile.WriteLine(item.ToString()); } foreach (var item in listBox3.Items) { SaveFile.Write("f3 "); // SaveFile.Write(" , "); SaveFile.WriteLine(item.ToString()); } SaveFile.ToString(); SaveFile.Close(); }
/** HTML保存到本地 **/ public static void GetToLocalHtml1() { var url = "http://stock.10jqka.com.cn/fincalendar.shtml#2015-12-18"; string strBuff = "";//定义文本字符串,用来保存下载的html int byteRead = 0; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); //若成功取得网页的内容,则以System.IO.Stream形式返回,若失败则产生ProtoclViolationException错 误。在此正确的做法应将以下的代码放到一个try块中处理。这里简单处理 Stream reader = webResponse.GetResponseStream(); ///返回的内容是Stream形式的,所以可以利用StreamReader类获取GetResponseStream的内容,并以StreamReader类的Read方法依次读取网页源程序代码每一行的内容,直至行尾(读取的编码格式:UTF8) StreamReader respStreamReader = new StreamReader(reader, Encoding.UTF8); ///分段,分批次获取网页源码 char[] cbuffer = new char[1024]; byteRead = respStreamReader.Read(cbuffer, 0, 256); string htm = ""; while (byteRead != 0) { string strResp = new string(cbuffer, 0, byteRead); strBuff = strBuff + strResp; byteRead = respStreamReader.Read(cbuffer, 0, 256); } using (StreamWriter sw = new StreamWriter("d:\\GetHtml.html"))//将获取的内容写入文本 { htm = sw.ToString();//测试StreamWriter流的输出状态,非必须 sw.Write(strBuff); } }
public static string Dump(this object element) { var memoryStream = new MemoryStream(); TextWriter textWriter = new StreamWriter(memoryStream); ObjectDumper.Write(element, 3, textWriter); return textWriter.ToString(); }
public string Minify(TextReader reader, StreamWriter writer) { sb = writer; tr = reader; theA = '\n'; theB = 0; theLookahead = EOF; cssmin(); return sb.ToString(); }
private void button2_Click(object sender, EventArgs e) { File.Delete(_Path); System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(_Path); SaveFile.WriteLine(listBox1.Items); SaveFile.ToString(); SaveFile.Close(); if (File.Exists(_Path)) { MessageBox.Show("Programs saved!"); } }
public void Guardar() { try { GuardarCadenaConexion(Properties.RutaBaseDatos); using (var sw = new StreamWriter(Application.StartupPath + ConfigurationManager.AppSettings["SettingsFolder"] + ConfigurationManager.AppSettings["SettingsName"])) { XmlSerializer serializer = new XmlSerializer(typeof(SettingsApplicationProperties)); serializer.Serialize(sw, Properties); sw.ToString(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public static void GuardarImpresoras(List<Impresora> impresoras) { try { if (!Directory.Exists(_folderSettings)) Directory.CreateDirectory(_folderSettings); string file = _folderSettings + ConfigurationManager.AppSettings["FilePrinter"] + ".xml"; using (var sw = new StreamWriter(file)) { XmlSerializer serializer = new XmlSerializer(typeof(List<Impresora>)); serializer.Serialize(sw, impresoras); sw.ToString(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
private void SaveTxtAwayTeam() { if (!string.IsNullOrEmpty(FilePath)) { try { string filename = (DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString() + "-AwayTeam-" + label4.Text + "-" + label5.Text + ".txt").ToLower(); var engname = String.Join("", filename.Normalize(NormalizationForm.FormD) .Where(c => char.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)); System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(FilePath + "\\" + engname); foreach (var item in listBox2.Items) { SaveFile.WriteLine(item.ToString()); } SaveFile.ToString(); SaveFile.Close(); } catch { } } }
public void GenerarProperties() { try { Properties.EsServidor = false; Properties.PrimeraArranque = true; Properties.TecladoPantalla = false; Properties.SplasImage = null; using (var sw = new StreamWriter(Application.StartupPath + ConfigurationManager.AppSettings["SettingsFolder"] + ConfigurationManager.AppSettings["SettingsName"])) { XmlSerializer serializer = new XmlSerializer(typeof(SettingsApplicationProperties)); serializer.Serialize(sw, Properties); sw.ToString(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public void SaveToFile(string path) { try { var serializer = new XmlSerializer (typeof(AppSettings)); using (var file = new FileStream(path, FileMode.Create)) { using (StreamWriter stream = new StreamWriter(file, Encoding.UTF8)) { Console.WriteLine (stream.ToString ()); serializer.Serialize (stream, this); } file.Close (); } Console.WriteLine ("Settings save to: " + path + " "); } catch (Exception e) { Console.WriteLine ("Can`t save settings: " + path + " " + e.Message); } }
/** * 保存到本地HTML **/ public static string GetToLocalHtml(string url, string exportPath) { string htm = ""; try { WebClient webClient = new WebClient(); webClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据 Byte[] pageData = webClient.DownloadData(url); string pageHtml = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句 //string pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句 //string pageHtml = Encoding.GetEncoding("GBK").GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句 using (StreamWriter sw = new StreamWriter(exportPath))//将获取的内容写入文本 { htm = sw.ToString();//测试StreamWriter流的输出状态,非必须 sw.Write(pageHtml); } } catch (WebException webEx) { Console.WriteLine(webEx.Message); } return exportPath; }
public string CombineScript(StreamWriter strWriter) { //Write all usings strWriter.WriteLine(UsingsText); Usings.ForEach(u => strWriter.WriteLine(u)); //Write class header strWriter.WriteLine(ClassBeginText); strWriter.WriteLine("public class " + ClassName + " : UniBehaviour {"); //Write variables Variables.ForEach(v => { //Write var data strWriter.WriteLine(TabSpaces + VarText + "%" + "{\"acceessModifier\":\"" + v.VarAccessModifier + "\"," + "\"type\":\"" + v.VarType + "\"," + "\"name\":\"" + v.VarName + "\"," + "\"value\":\"" + v.VarValue + "\"}"); //Write var code strWriter.WriteLine(TabSpaces + v.VarAccessModifier + " " + v.VarType + " " + v.VarName + " = " + v.VarValue + ";"); }); //Write events (they forming string with line end by themselves) Events.ForEach(e => { e.CombineScript(strWriter); }); //Write class end strWriter.WriteLine(ClassEndText); strWriter.WriteLine("}"); string result = strWriter.ToString(); strWriter.Close(); return result; }
static void Main(string[] args) { TextReader tr; TextWriter tw; string defaultEndpoint = "http://*****:*****@"C:\Users\Administrator\Documents\GitHub\LeanKit.Utilities\Validation.TestUtility\test.txt"; string defaultWritefile = @"C:\Users\Administrator\Documents\GitHub\LeanKit.Utilities\Validation.TestUtility\test2.txt"; string ep; string connectionString = null; string query = null; //handle options var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { if (options.inputFile != null) { try { tr = new StreamReader(options.inputFile); Console.WriteLine(String.Format("Input file is set as {0}", tr.ToString())); } catch (Exception ex) { Console.WriteLine(@"Cannot locate this file. Setting input at default value."); tr = new StreamReader(defaultReadfile); } } else { tr = new StreamReader(defaultReadfile); Console.WriteLine(@"Input file is set as C:\Users\Administrator\Documents\GitHub\LeanKit.Utilities\Validation.TestUtility\test.txt"); } if (options.outputFile != null) { tw = new StreamWriter(options.outputFile); Console.WriteLine(String.Format("Output file is set as {0}", tw.ToString())); } else { tw = new StreamWriter(defaultWritefile); Console.WriteLine(defaultWritefile); } if (options.url != null) { string url = options.url; Console.WriteLine(String.Format(@"The url which will be scrapped is {0}", url)); } if (options.endpoint != null) { ep = options.endpoint; } else { ep = defaultEndpoint; Console.WriteLine(String.Format(@"The api endpoint set is{0}", defaultEndpoint)); } //Check and set database variables if (options.dbserver != null && options.dbname != null && options.dbuser != null && options.dbpassword != null && options.dbquery != null) { connectionString = String.Format(@"Data Source = {0}; Initial Catalog ={1}; Persist Security Info = true; User ID={2};Password={3}", options.dbserver, options.dbname, options.dbuser, options.dbpassword); query = options.dbquery; } } else { string url; tr = new StreamReader(defaultReadfile); tw = new StreamWriter(defaultWritefile); ep = defaultEndpoint; connectionString = null; } //////////////////////////////////////// if (options.url != null) //if scraping a url { Task<String> resp = scraper(options.url); if (resp.Result != null) { Task<String> apiresp = ApiRequest(resp.Result, ep); if (apiresp.Result != null) { string s = apiresp.Result; tw.WriteLine("\tResult:\t{0}\n", s); } else { tw.WriteLine("\tResult: Format accepted\n"); } } else { Console.WriteLine("No conent returned by requested URL\n"); } } else if (options.dbserver != null && options.dbname != null && options.dbuser != null && options.dbpassword != null && options.dbquery != null) //else if testing against database { sqlTester(connectionString, query, tw, ep); } else //else Basic check against file { string xssrequest; while ((xssrequest = tr.ReadLine()) != null) { Task<String> resp = ApiRequest(xssrequest, ep); if (resp != null) { string s = resp.Result; tw.WriteLine("Result:\t{0}\n", s); } } } //close files if (tr != null) { tr.Close(); } tw.Close(); Console.ReadLine(); }
private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex > -1) { label1.Text = ""; // Dialog to select folder where videos are placed FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Select folder where videos are placed"; DialogResult result = fbd.ShowDialog(); // Output Folder to place videos FolderBrowserDialog fbd2 = new FolderBrowserDialog(); fbd2.Description = "Select the folder where you wanna place the videos"; DialogResult result2 = fbd2.ShowDialog(); ///////////////////////////////////// // Displays an OpenFileDialog so the user can select a Python Files /* OpenFileDialog openFileDialog1 = new OpenFileDialog(); * //openFileDialog1.Filter = "BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff|All Graphics Types|*.bmp;*.jpg;*.jpeg;*.png"; * openFileDialog1.Filter = "Python Files|*.py"; * openFileDialog1.Title = "Python file containing watermarking code"; * openFileDialog1.ShowDialog(); * string pythonFile = openFileDialog1.FileName.ToString(); * * * // TO select the Python Exe file * //openFileDialog1.Filter = "BMP|*.bmp|GIF|*.gif|JPG|*.jpg;*.jpeg|PNG|*.png|TIFF|*.tif;*.tiff|All Graphics Types|*.bmp;*.jpg;*.jpeg;*.png"; * openFileDialog1.Filter = "Exe Files|*.exe"; * openFileDialog1.Title = "Python .exe File"; * openFileDialog1.ShowDialog(); * string pythonExeFile = openFileDialog1.FileName.ToString(); */ // video formats ///////////////////////////////////// if (!string.IsNullOrWhiteSpace(fbd.SelectedPath)) { //string[] files = Directory.GetFiles(fbd.SelectedPath); // string[] files = Directory.GetFiles(@fbd.SelectedPath, "*.mp4"); //string[] extensions = { ".mp4", ".mkv", ".avi"}; string[] extensions = { comboBox1.SelectedItem.ToString() }; string[] files = Directory.GetFiles(@fbd.SelectedPath, "*.*") .Where(f => extensions.Contains(System.IO.Path.GetExtension(f).ToLower())).ToArray(); // C: \Users\john\gcc\bin using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\file_names.txt")) { // If the line doesn't contain the word 'Second', write the line to the file. file.WriteLine(fbd.SelectedPath.ToString()); // folder path file.WriteLine(comboBox1.SelectedItem.ToString()); file.WriteLine(textBox1.Text.ToString()); // Text to be written on video file.WriteLine(fbd2.SelectedPath.ToString()); // Text to be written on video } // end /// Python COde /// // Selected files from the directory int i = 0; foreach (string file in files) { richTextBox1.Text += "################# Video #" + ++i + " ############\n"; richTextBox1.Text += file.ToString() + "\n"; // Showing status //////////////////////////////////////// i++; } // foreach end // Executing python file using batch code System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = @"C:\Users\1.bat"; proc.Start(); label1.Text = "Done"; //////////////////////////////// } } else { label1.Text = "Please select a video format"; } //Display result } // function end