当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.StreamWriter.Close方法代码示例

本文整理汇总了C#中System.IO.StreamWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamWriter.Close方法的具体用法?C# System.IO.StreamWriter.Close怎么用?C# System.IO.StreamWriter.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamWriter的用法示例。


在下文中一共展示了System.IO.StreamWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtractTextFromPdf

        public static string ExtractTextFromPdf(string path)
        {
            ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();

            using (PdfReader reader = new PdfReader(path))
            {
                StringBuilder text = new StringBuilder();

                for (int page = 1; page <= reader.NumberOfPages; page++)
                {
                    ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();

                    string currentText = PdfTextExtractor.GetTextFromPage(reader, page, strategy);

                    currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
                    text.Append(currentText);
                }

                System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
                file.WriteLine(text);

                file.Close();

                return text.ToString();
            }
        }
开发者ID:james-catterall,项目名称:Parsing-to-file,代码行数:26,代码来源:Program.cs

示例2: TryPrint

        public void TryPrint(string zplCommands)
        {
            try
            {
                // Open connection
                System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
                client.Connect(this.m_IPAddress, this.m_Port);

                // Write ZPL String to connection
                System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
                writer.Write(zplCommands);
                writer.Flush();

                // Close Connection
                writer.Close();
                client.Close();
            }
            catch (Exception ex)
            {
                this.m_ErrorCount += 1;
                if(this.m_ErrorCount < 10)
                {
                    System.Threading.Thread.Sleep(5000);
                    this.TryPrint(zplCommands);
                }
                else
                {
                    throw ex;
                }
            }
        }
开发者ID:ericramses,项目名称:YPILIS,代码行数:31,代码来源:ZPLPrinter.cs

示例3: button3_Click

 private void button3_Click(object sender, EventArgs e)
 {
     //http://vspro1.wordpress.com/2011/02/28/export-to-a-text-file-from-a-datagridview-control/
     System.IO.StreamWriter file = new System.IO.StreamWriter(@"TextFile.txt");
     try
     {
         string sLine = "";
         //This for loop loops through each row in the table
         for (int r = 0; r <= dataGridView1.Rows.Count - 1; r++)
         {
             //This for loop loops through each column, and the row number
             //is passed from the for loop above.
             for (int c = 0; c <= dataGridView1.Columns.Count - 1; c++)
             {
                 sLine = sLine + dataGridView1.Rows[r].Cells[c].Value;
                 if (c != dataGridView1.Columns.Count - 1)
                 {
                     //A comma is added as a text delimiter in order
                     //to separate each field in the text file.
                     //You can choose another character as a delimiter.
                     sLine = sLine + ",";
                 }
             }
             //The exported text is written to the text file, one line at a time.
             file.WriteLine(sLine);
             sLine = "";
         }
         file.Close();
        // System.Windows.Forms.MessageBox.Show("Export Complete.", "Program Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (System.Exception err)
     {
         System.Windows.Forms.MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         file.Close();
     }
     DialogResult show1 = MessageBox.Show("Muon Mo Folder Khong","Important",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
     switch (show1)
     {
         case DialogResult.Abort:
             break;
         case DialogResult.Cancel:
             break;
         case DialogResult.Ignore:
             break;
         case DialogResult.No:
             break;
         case DialogResult.None:
             break;
         case DialogResult.OK:
             break;
         case DialogResult.Retry:
             break;
         case DialogResult.Yes:
             System.Diagnostics.Process.Start(System.Environment.CurrentDirectory);
             break;
         default:
             break;
     }
 }
开发者ID:tranquangchau,项目名称:cshap-2008-2013,代码行数:59,代码来源:Form1.cs

示例4: BugReport

 public static void BugReport(string program, string desc, Exception ex, string data)
 {
     try
     {
         System.Diagnostics.Process.Start(DeveloperIssuePostURL(program, desc, ex, data));
     }
     catch (Win32Exception)
     {
         try
         {
             // data passed too small/big
             System.Diagnostics.Process.Start(DeveloperIssuePostURL(program, program, ex, data, false));
         }
         catch 
         {
             string report = DeveloperIssuePostURL(program, desc, ex, data);
             System.IO.StreamWriter sw = new System.IO.StreamWriter("tempreport.txt");
             sw.WriteLine(report);
             sw.Flush();
             sw.Close();
             System.Diagnostics.Process.Start(Environment.SystemDirectory+"\\notepad.exe tempreport.txt");
             System.Diagnostics.Process.Start(DeveloperIssuePostURL(program, desc, null, Environment.NewLine + " PASTE NOTEPAD CONTENTS HERE"));
         }
     }
 }
开发者ID:antonywu,项目名称:tradelink,代码行数:25,代码来源:CrashReport.cs

示例5: ServicioVerificadorPLD

        public BIM.BusinessEntities.VerificadorPLD ServicioVerificadorPLD(BIM.BusinessEntities.BitacoraPLD parametros)
        {
            BIM.BusinessEntities.VerificadorPLD result = null;
            try
            {
                result = (new VerificadorPLDLogic()).ServicioVerificadorPLD(parametros);
            }
            catch (Exception ex)
            {
#if(DEBUG)


                const string fic = @"C:\inetpub\wwwroot\PLD\Prueba.txt";
                string texto = ex.Message;

                System.IO.StreamWriter sw = new System.IO.StreamWriter(fic);
                sw.WriteLine(texto);
                sw.Close();

                
                //Console.WriteLine("Error en VerificadorPLDServices.ServicioVerificadorPLD: " + ex.Message);

                //if (!EventLog.SourceExists(cs))
                //    EventLog.CreateEventSource(cs, "Application");

                //EventLog.WriteEntry(cs, ex.Message, EventLogEntryType.Error);
#else
                    EventLogManager.LogErrorEntry("Error en VerificadorPLDServices.ServicioVerificadorPLD: " + ex.Message);
                    //TODO: Codificar envío de notificación de error al EventLog
#endif
            }
            return result;
        }
开发者ID:vnktop,项目名称:PLD-BIM,代码行数:33,代码来源:Service2.svc.cs

示例6: Main

        static void Main(string[] args)
        {
            string[] funcListUrls = {
                                        //"http://www.xqueryfunctions.com/xq/c0008.html",
                                        //"http://www.xqueryfunctions.com/xq/c0011.html",
                                        //"http://www.xqueryfunctions.com/xq/c0002.html",
                                        //"http://www.xqueryfunctions.com/xq/c0013.html",
                                        //"http://www.xqueryfunctions.com/xq/c0015.html",
                                        "http://www.xqueryfunctions.com/xq/c0026.html",
                                        "http://www.xqueryfunctions.com/xq/c0033.html",
                                        "http://www.xqueryfunctions.com/xq/c0021.html",
                                        "http://www.xqueryfunctions.com/xq/c0023.html",
                                        "http://www.xqueryfunctions.com/xq/c0072.html"
                                    };

            foreach (string funcListUrl in funcListUrls)
            {
                FuncList[] funcLists = ParseFuncList(funcListUrl);
                foreach (FuncList funcList in funcLists)
                {
                    System.IO.StreamWriter testFile = new System.IO.StreamWriter(TESTCASE_FILE, true);
                    testFile.WriteLine("\n<!-- " + funcList.funcName + " - " + funcList.subcat + ": " + funcList.funclist.Length + " cases -->");
                    testFile.Close();
                    testFile = null;
                    foreach (string name in funcList.funclist)
                    {
                        string url = "http://www.xqueryfunctions.com/xq/functx_" + name + ".html";
                        Console.WriteLine("Parsing " + url + " ...");
                        ParseURL(funcList.funcName, funcList.subcat, url);
                    }
                }
            }
        }
开发者ID:yezilaoda,项目名称:mytoolkits,代码行数:33,代码来源:Program.cs

示例7: ButtonPhoto_Click

 private void ButtonPhoto_Click(object sender, EventArgs e)
 {
     var flickr = new Flickr(Program.ApiKey, Program.SharedSecret, Program.AuthToken);
     // Referrers
     DateTime day = DateTime.Today;
     var statfile = new System.IO.StreamWriter("stats_dom.csv");
     var reffile = new System.IO.StreamWriter("stats_referrers.csv");
     while (day > Program.LastUpdate)
     {
         try
         {
             var s = flickr.StatsGetPhotoDomains(day, 1, 100);
             day -= TimeSpan.FromDays(1);
             StatusLabel.Text = "Chargement des domaines " + day.ToShortDateString();
             Application.DoEvents();
             statfile.Write(Utility.toCSV(s, day.ToShortDateString()));
             foreach (StatDomain dom in s)
             {
                 var r = flickr.StatsGetPhotoReferrers(day, dom.Name, 1, 100);
                 reffile.Write(Utility.toCSV(r, day.ToShortDateString() + ";" + dom.Name));
             }
         }
         catch (FlickrApiException ex)
         {
             MessageBox.Show("Erreur lors du chargement des domaines référents du "
                 + day.ToShortDateString() + " : " + ex.OriginalMessage,
                 "Erreur", MessageBoxButtons.OK);
             break;
         }
     }
     statfile.Close();
 }
开发者ID:remyoudompheng,项目名称:flickrstats,代码行数:32,代码来源:MainForm.cs

示例8: btnSubmit_Click

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //string xml;
               Contact contact = new Contact();

            contact.companyName = txtCompany.Text;
            contact.firstName = txtFName.Text;
            contact.middleName = txtMName.Text;
            contact.lastName = txtLName.Text;
            contact.liscence = txtLicense.Text;
            contact.phone = txtPhone.Text;
            contact.cell = txtCell.Text;
            contact.email = txtEmail.Text;
            contact.buildingLiscence = txtBuildingLicense.Text;
            contact.streetNumber = txtStreetNumber.Text;
            contact.streetName = txtStreetName.Text;
            contact.type = txtType.Text;
            contact.streetName2 = txtStreetName2.Text;
            contact.city = txtCity.Text;
            contact.state = txtState.Text;
            contact.zip = txtZip.Text;
            System.IO.StreamWriter file = new System.IO.StreamWriter(@"Contact.xml");
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(contact.GetType());
            x.Serialize(file, contact);
            file.Close();
        }
开发者ID:sunelaitisd088,项目名称:AberdeenPermitting,代码行数:26,代码来源:ContactInfo.cs

示例9: save

        /// <summary>
        /// Saves the colourz
        /// </summary>
        public void save()
        {
            if (!System.IO.Directory.Exists(Constants.CACHE_PATH))
            {
                System.IO.Directory.CreateDirectory(Constants.CACHE_PATH);
            }

            if (!System.IO.Directory.Exists(Constants.CACHE_PATH))
            {
                Console.WriteLine("Created directory");
                System.IO.Directory.CreateDirectory(Constants.CACHE_PATH);
            }

            System.IO.File.WriteAllBytes(Constants.CACHE_PATH + "Saved Colours.txt", new byte[0]);
            System.IO.StreamWriter file = new System.IO.StreamWriter(Constants.CACHE_PATH + "Saved Colours.txt", true);
            
            string saveText = "";
            for(int i = 0; i < stack.Children.Count; i++)
            {
                SavedColour s = (SavedColour)stack.Children[i];

                if(i != stack.Children.Count)
                    saveText += s.hex + ";";
            }
            file.WriteLine(saveText);
            file.Flush();
            file.Close();
        }
开发者ID:wolfbytestudio,项目名称:Colourz,代码行数:31,代码来源:ColourzSaver.cs

示例10: Send

        public void Send(object sender, EventArgs args)
        {
            try
            {
                var publishArgs = args as Sitecore.Events.SitecoreEventArgs;

                var publisher = publishArgs.Parameters[0] as Sitecore.Publishing.Publisher;

                var publisherOptions = publisher.Options;

                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("localhost");

                mail.From = new MailAddress("[email protected]");
                mail.To.Add("[email protected]");
                mail.Subject = "Someone published the item " + publisherOptions.RootItem.Paths.FullPath;
                mail.Body = publisherOptions.RootItem.Fields["body"].Value;
                SmtpServer.Send(mail);

                string lines = publisherOptions.RootItem.Fields["body"].Value;

                // Write the string to a file.
                System.IO.StreamWriter file = new System.IO.StreamWriter("D:\\Git\\Eduserv-Github-Example\\Source\\Website\\BritishLibrary.Website\\test.xml");
                file.WriteLine(lines);

                file.Close();

            }
            catch (Exception ex)
            {
                Console.WriteLine("Seems some problem!");
            }
        }
开发者ID:Adamsimsy,项目名称:Eduserv-Github-Example,代码行数:33,代码来源:SendEmailNotification.cs

示例11: generateDmcColors

        public void generateDmcColors()
        {
            System.IO.StreamReader inFile = new System.IO.StreamReader(webPageDirectory);
            System.IO.StreamWriter outFile = new System.IO.StreamWriter(dmcDirectory, true);
            string line = "", dmc = "", name = "", color = "";

            while ((line = inFile.ReadLine()) != null)
            {
                if (line.Trim().StartsWith("<TD><FONT face=\"arial, helvetica, sans-serif\" size=2>") && !line.Trim().EndsWith("Select view")) //find dmc
                {
                    dmc = line.Trim().Split(new string[] { "<TD><FONT face=\"arial, helvetica, sans-serif\" size=2>" }, StringSplitOptions.None)[1];
                    dmc = dmc.Split(new string[] { "<" }, StringSplitOptions.None)[0];
                }
                else if (line.Trim().StartsWith("<TD noWrap><FONT face=\"arial, helvetica, sans-serif\" size=2>"))  //find name
                {
                    //issue with line continuation
                    name = line.Trim().Split(new string[] { "<TD noWrap><FONT face=\"arial, helvetica, sans-serif\" size=2>" }, StringSplitOptions.None)[1];
                    name = name.Split(new string[] { "<" }, StringSplitOptions.None)[0];
                    if (!line.Trim().EndsWith("</FONT></TD>"))
                    {
                        line = inFile.ReadLine();
                        name = name + " " + line.Trim().Split(new string[] { "<" }, StringSplitOptions.None)[0];
                    }
                }
                else if (line.Trim().StartsWith("<TD bgColor=") && line.Trim().Contains(">&nbsp;</TD>"))
                {
                    color = line.Trim().Split(new string[] { "<TD bgColor=" }, StringSplitOptions.None)[1];
                    color = color.Split(new string[] { ">" }, StringSplitOptions.None)[0];
                    outFile.WriteLine(dmc + ";" + name + ";" + color);
                }
            }
            inFile.Close();
            outFile.Close();
            Console.ReadLine();
        }
开发者ID:rabidllamaofdoom,项目名称:PixelXStitchy,代码行数:35,代码来源:ColorFinder.cs

示例12: SaveBtn_Click

        private void SaveBtn_Click(object sender, EventArgs e)
        {
            string path = pathText.Text;

            if (path.Length < 1 || path.Trim().Length < 1) {
                MessageBox.Show("Invalid path name.", "Invalid path");
                return;
            }

            foreach (char c in System.IO.Path.GetInvalidFileNameChars()) {
                if (path.Contains(c)) {
                    MessageBox.Show("Invalid character '" + c + "' in file path.", "Invalid path");
                    return;
                }
            }

            if (!System.IO.Path.HasExtension(path))
                path += ".lua";

            if (!overwriteCheckBox.Checked && System.IO.File.Exists(path)) {
                MessageBox.Show("File '" + path + "' already exists.", "File already exists");
                return;
            }

            string lua = Derma.GenerateLua();

            System.IO.TextWriter file = new System.IO.StreamWriter(path);
            file.Write(lua);
            file.Close();

            MessageBox.Show("Lua generated to file '" + path + "'.", "Success");

            this.Close();
        }
开发者ID:alandoherty,项目名称:dermadesignerb,代码行数:34,代码来源:SaveLuaFile.cs

示例13: GravarDados

 private void GravarDados(ClienteInfo cli)
 {
     System.IO.StreamWriter sw = new System.IO.StreamWriter(cli.NomeArquivo(),true);
     //aqui a data é formatada
     sw.WriteLine(cli.Nome + ";" +cli.Email + ";" + cli.Telefone + ";" + cli.ClienteDesde.ToShortDateString());
     sw.Close();
 }
开发者ID:tca85,项目名称:ASP.NET,代码行数:7,代码来源:clientesForm.cs

示例14: writeFile

 /// <summary>
 /// Prends en parametres le nom et une chaine de caracteres
 /// Ecrit la chaine de caracteres dans le fichier
 /// Cree le fichier si il n'existe pas
 /// </summary>
 /// <param name="name">Nom du fichier</param>
 /// <param name="content">Contenu du fichier</param>
 public static void writeFile(string name, string content)
 {
     try
     {
         System.IO.StreamWriter outstream = new System.IO.StreamWriter(name);
         outstream.Write(content);
         outstream.Close();
     }
     catch (System.IO.DirectoryNotFoundException)
     {
         try
         {
             System.IO.Directory.CreateDirectory(name);
             System.IO.Directory.Delete(name);
             writeFile(name, content);
         }
         catch (Exception)
         {
             Console.WriteLine("FileStream.writeFile : Erreur lors de la creation du repertoire " + name);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("FileStream.writeFile : Erreur lors de l'ecriture dans le fichier " + name);
     }
 }
开发者ID:eddydg,项目名称:The-Revenge-Of-the-Dark-Side,代码行数:33,代码来源:IO.cs

示例15: WriteLog

 private void WriteLog (Exception e)
 {
     var ws = new System.IO.StreamWriter("error.log",true );
     ws.WriteLine(e);
     ws.WriteLine("");
     ws.Close();
 }
开发者ID:powerhai,项目名称:Jinchen,代码行数:7,代码来源:App.xaml.cs


注:本文中的System.IO.StreamWriter.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。