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


C# StringWriter.Close方法代码示例

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


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

示例1: btnExport_Click

        protected void btnExport_Click(Object sender, EventArgs e)
        {
            Response.ContentEncoding = Encoding.UTF8;
            Response.ContentType = "application/ms-excel";
            Response.Charset = "utf-8";
            Response.AppendHeader("Content-Disposition",
                "attachment;filename=" + HttpUtility.UrlEncode("指标历史数据.xls",
                System.Text.Encoding.UTF8).ToString());
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            int RecordCount = 0;
            DateTime StartDate = Convert.ToDateTime(txtStartDate.Text);
            DateTime EndDate = Convert.ToDateTime(txtEndDate.Text);
            String ECID = Request.Params["ECID"];
            using (ECHistoryDataAccess DataAccess = new ECHistoryDataAccess()) {
                ECDataRepeater.DataSource = DataAccess.GetECHourData(ECID, StartDate, EndDate,
                   1, 20000, out RecordCount);
                ECDataRepeater.DataBind();
                ECDataRepeater.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.Flush();
                Response.End();
                sw.Close();
                sw.Dispose();
            }
            DataBind();
        }
开发者ID:JackSunny1980,项目名称:SISKPI,代码行数:28,代码来源:ECChartPage.aspx.cs

示例2: SerializeTest

        public void SerializeTest()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(EmailBroadcast));
            Order order = new EmailBroadcast()
            {
                DisplayName = "jt",
                EmailSubject = "test email message",
                SendTimeUTC = DateTime.UtcNow,
                TextBody = TextBody.FromText("This is a test email")
            };

            StringBuilder sb = new StringBuilder();
            TextWriter writer = new StringWriter(sb);
            serializer.Serialize(writer, order);
            writer.Close();

            Assert.IsNotNull(sb);
            Assert.IsTrue(!string.IsNullOrEmpty(sb.ToString()));

            TextReader tr = new StringReader(sb.ToString());
            object obj = serializer.Deserialize(tr);
            var deserializedMessage = obj as EmailBroadcast;
            Assert.IsTrue(deserializedMessage.DisplayName == "jt");
            Assert.IsTrue(deserializedMessage.EmailSubject == "test email message");
            var xml = deserializedMessage.ToXml();
        }
开发者ID:julyfortoday,项目名称:APIClient,代码行数:26,代码来源:EmailBroadcastTest.cs

示例3: CreateSpecs

        public string CreateSpecs(out int specCount)
        {
            var files = FindSpecFiles().ToArray();
            specCount = files.Length;
            if (specCount < 1)
                return string.Empty;

            var compile = new CodeCompileUnit();

            var globalns = new CodeNamespace();
            globalns.Imports.Add(new CodeNamespaceImport("NUnit.Framework"));
            globalns.Imports.Add(new CodeNamespaceImport(config.MyNamespace));
            compile.Namespaces.Add(globalns);
            var specNamespace = new CodeNamespace(config.TargetNamespace + ".ChutzpahSpecs");
            compile.Namespaces.Add(specNamespace);

            foreach (var fileInfo in files)
            {
                AddSpec(specNamespace, fileInfo);
            }
            //specNamespace.Types.AddRange(files.Select(CreateSpec).ToArray());

            var provider = CreateProvider();
            var options = new CodeGeneratorOptions { BracingStyle = "C", BlankLinesBetweenMembers = false };
            var stringBuilder = new StringBuilder();
            using (var writer = new StringWriter(stringBuilder))
            {
                provider.GenerateCodeFromCompileUnit(compile, writer, options);
                writer.Flush();
                writer.Close();
            }
            var result = stringBuilder.ToString();
            return result;
        }
开发者ID:vurt007,项目名称:ghost-bridge,代码行数:34,代码来源:NUnitCodeProvider.cs

示例4: Serialize

        public static string Serialize(UserProfileData profile)
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.Indented;
            xtw.WriteStartDocument();
            
            xtw.WriteStartElement("user_profile");
            xtw.WriteAttributeString("major_version", MAJOR_VERSION.ToString());
            xtw.WriteAttributeString("minor_version", MINOR_VERSION.ToString());
                       
            xtw.WriteElementString("name", profile.Name);
            xtw.WriteElementString("id", profile.ID.ToString());
            xtw.WriteElementString("about", profile.AboutText);
  
            // Not sure if we're storing this yet, need to take a look
//            xtw.WriteElementString("Url", profile.Url);
            // or, indeed, interests

            xtw.WriteEndElement();
            
            xtw.Close();
            sw.Close();
            
            return sw.ToString();
        }
开发者ID:AlphaStaxLLC,项目名称:taiga,代码行数:26,代码来源:UserProfileSerializer.cs

示例5: Init

        public void Init()
        {
            _server = new TmsServer();
            //TileSizeX = 256;
            //TileSizeY = 256;

            // save coordinate system in xml format
            XmlWriterSettings settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                Encoding = Encoding.UTF8,
                Indent = true
            };

            StringWriter strWriter = new StringWriter();
            XmlWriter writer = XmlWriter.Create(strWriter, settings);
            writer.WriteStartDocument();
            writer.WriteStartElement("data");
            writer.WriteStartElement("coordinateSystem");
            writer.WriteElementString("name", "Mercator");
            writer.WriteElementString("datum", "World Geodetic 1984 (WGS84) Auto");
            writer.WriteElementString("system", "Mercator");
            writer.WriteElementString("unit", "Meter");
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();

            _coordinateSystem = strWriter.ToString();
            strWriter.Close();
        }
开发者ID:jmkelly,项目名称:Manifold-ISIs,代码行数:32,代码来源:DownloadTests.cs

示例6: Initialize

        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
            Debug.Assert(Request.IsAuthenticated);

            var user = User.Identity.Name;
            var dCase = _ctx.DCases.FirstOrDefault(c => c.Owner == user && c.Name == StandardCases.MesoWind);
            if (dCase == null)
            {
                dCase = new DCase
                {
                    Id = Guid.NewGuid(),
                    Name = StandardCases.MesoWind,
                    Owner = user,
                    Created = DateTime.UtcNow
                };
                // Model contains points from both databases by default
                var model = new VMesoWind();
                ItemsCount(model);

                var serializer = new XmlSerializer(typeof (VMesoWind));
                using (var writer = new StringWriter())
                {
                    serializer.Serialize(writer, model);
                    dCase.Model = writer.ToString();
                    writer.Close();
                }
                _ctx.DCases.AddObject(dCase);
                _ctx.SaveChanges();
            }
            base.Initialize(requestContext);
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:32,代码来源:MesoWindController.cs

示例7: WriteErrorToHtml

        public static void WriteErrorToHtml(string HtmlName, string TestID, string TestStep, string ErrorStack, string ScreenshotFile, string errorSummary)
        {
            System.IO.FileStream fs = new FileStream(HtmlName, FileMode.Create);

            StringWriter stringWriter = new StringWriter();
            using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
            {
                w.WriteLine("<html>");
                w.Write("<h1>");
                w.Write("TestName:"+TestID);
                w.WriteLine("</h1>");
                w.Write("<h2>");
                w.Write("Step Number:"+TestStep);
                w.WriteLine("</h2>");
                w.WriteLine("<body>");
                w.WriteLine("<img src='" + ScreenshotFile + "' style='padding:1px;border:thin solid black;' width=600 height=600  alt='" + ScreenshotFile + "' />");
                w.WriteLine("</body>");
                w.WriteLine("<br/>");
                w.WriteLine("Error: "+errorSummary);
                w.WriteLine("<br/>");
                w.WriteLine("Error stack trace:");
                w.WriteLine("<br/>");
                w.WriteLine(ErrorStack);
                w.WriteLine("</body>");
                w.WriteLine("</html>");
            }
            stringWriter.Close();
            fs.Close();
            return;
        }
开发者ID:reggieesposa,项目名称:CustomTestAutomation,代码行数:30,代码来源:GeneralUtility.cs

示例8: FormatExceptionHandlingExceptionMessage

        /// <summary>
		/// Formats an exception message so that it can be sent to the event log later, by someone else.
        /// </summary>
        /// <param name="policyName">The policy that is running.</param>
        /// <param name="offendingException">The exception that occured in the chain.</param>
        /// <param name="chainException">The exception when the chain failed.</param>
        /// <param name="originalException">The original exception.</param>		
		public static string FormatExceptionHandlingExceptionMessage(string policyName, Exception offendingException, Exception chainException, Exception originalException)
        {
            if(policyName == null) throw new ArgumentNullException("policyName");

            StringBuilder message = new StringBuilder();
            StringWriter writer = null;
			string result = null;
            try
            {
                writer = new StringWriter(message, CultureInfo.CurrentCulture);

                if (policyName.Length > 0)
                {
                    writer.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.PolicyName, policyName));
                }

                FormatHandlingException(writer, Resources.OffendingException, offendingException);
                FormatHandlingException(writer, Resources.OriginalException, originalException);
                FormatHandlingException(writer, Resources.ChainException, chainException);
            }
            finally
            {
                if (writer != null)
                {
					result = writer.ToString();
                    writer.Close();
                }
            }

			return result;
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:38,代码来源:ExceptionUtility.cs

示例9: createContent

        private void createContent(String varName, Object objectToPass, StringReader reader, String outputFileName)
        {
            Dictionary<String, Object> map = new Dictionary<String, Object>();
            map.Add(varName, objectToPass);

            String outputContent = null;
            StringTemplateGroup group = new StringTemplateGroup(reader);
            var contentTemplate = group.GetInstanceOf("Content");
            contentTemplate.Attributes = map;
            outputContent = contentTemplate.ToString();
            //StringBuilder sb = new StringBuilder(outputContent);
            StringWriter writer = new StringWriter(new StringBuilder(outputContent));
            writer.Flush();
            StreamWriter fileWriter = null;
            try
            {
                fileWriter = new StreamWriter(outputFileName + "/report.html.data");
                fileWriter.Write(writer.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            writer.Close();
            fileWriter.Close();
        }
开发者ID:VTAF,项目名称:VirtusaCodedUIRuntime,代码行数:27,代码来源:Generator.cs

示例10: ApplyTransaction

        public void ApplyTransaction(IList<Triple> preconditions, IList<Triple> deletePatterns, IList<Triple> inserts, 
            string updateGraphUri )
        {
            var deleteData = new StringWriter();
            var dw = new BrightstarTripleSinkAdapter(new NQuadsWriter(deleteData, updateGraphUri));
            foreach (Triple triple in deletePatterns)
            {
                dw.Triple(triple);
            }
            deleteData.Close();

            var addData = new StringWriter();
            var aw = new BrightstarTripleSinkAdapter(new NQuadsWriter(addData, updateGraphUri));
            foreach (Triple triple in inserts)
            {
                aw.Triple(triple);
            }
            addData.Close();

            var preconditionsData = new StringWriter();
            var pw = new BrightstarTripleSinkAdapter(new NQuadsWriter(preconditionsData, updateGraphUri));
            foreach (var triple in preconditions)
            {
                pw.Triple(triple);
            }
            preconditionsData.Close();

            PostTransaction(preconditionsData.ToString(), deleteData.ToString(), addData.ToString(), updateGraphUri);
        }
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:29,代码来源:BrightstarRestUpdatableStore.cs

示例11: UsingStringReaderAndStringWriter

        private void UsingStringReaderAndStringWriter()
        {
            Console.WriteLine("String Reader and String Writer example");
            Console.WriteLine("Some APIs expects TestWriter and TextReader but they can't work with string or StringBuilder. StringWriter and StringReader adapts to the interface of StringBuilder.");

            StringWriter stringWriter = new StringWriter();
            using (XmlWriter writer = XmlWriter.Create(stringWriter))
            {
                writer.WriteStartElement("book");
                writer.WriteElementString("price", "19.95");
                writer.WriteEndElement();
                writer.Flush();
            }

            string xml = stringWriter.ToString();
            Console.WriteLine("String created using StringWriter and XMLWriter is :");
            Console.WriteLine(xml);

            StringReader stringReader = new StringReader(xml);
            using (XmlReader reader = XmlReader.Create(stringReader))
            {
                reader.ReadToFollowing("price");
                decimal price = decimal.Parse(reader.ReadInnerXml(),new CultureInfo("en-US"));
                Console.WriteLine("Price read using String Reader and XMLReader is :" + price);
            }

            stringWriter.Close();
            stringReader.Close();
        }
开发者ID:mayankaggarwal,项目名称:MyConcepts,代码行数:29,代码来源:StringManipulationExamples.cs

示例12: ServerTMS

        public ServerTMS()
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.OmitXmlDeclaration = true;
            settings.Encoding = Encoding.UTF8;
            settings.Indent = true;

            StringWriter strWriter = new StringWriter();
            XmlWriter writer = XmlWriter.Create(strWriter, settings);
            writer.WriteStartDocument();
            writer.WriteStartElement("data");
            writer.WriteStartElement("coordinateSystem");
            writer.WriteElementString("name", "Mercator");
            writer.WriteElementString("datum", "World Geodetic 1984 (WGS84) Auto");
            writer.WriteElementString("system", "Mercator");
            writer.WriteElementString("unit", "Meter");
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();

            m_CoordinateSystem = strWriter.ToString();
            strWriter.Close();
            m_DefaultImageType = ".png";
            m_ReverseY = false;
            m_ScaleHi = 21;
            m_ScaleLo = 0;
            m_TileSizeX = 256;
            m_TileSizeY = 256;
            m_Name = "TMS Tile Coordinates";
            m_DefaultURL = "http://";
            ScaleNames = "0.675m,1.25m,2.5m,5m,10m,20 m,40 m,80 m,160 m,320 m,640 m,1.2km,2.5km,5km,10km,20km,40km,80km,160km,320km,640km,1280km";
        }
开发者ID:jmkelly,项目名称:Manifold-ISIs,代码行数:34,代码来源:Server.cs

示例13: Execute

 public void Execute(object parameter)
 {
     var collection = parameter as ObservableCollection<IDataItem>;
     if (collection != null)
     {
         var data = (ObservableCollection<IDataItem>) parameter;
         using (var stringWriter = new StringWriter())
         {
             using (var writer = XmlWriter.Create(stringWriter, new XmlWriterSettings {Indent = true}))
             {
                 writer.WriteStartDocument();
                 writer.WriteStartElement("data");
                 foreach (var dataItem in data)
                 {
                     writer.WriteStartElement("item");
                     writer.WriteString(dataItem.Value);
                     writer.WriteEndElement();
                 }
                 writer.WriteEndElement();
                 writer.WriteEndDocument();
                 writer.Flush();
             }
             stringWriter.Close();
             var client = new SaveXmlServiceClient();
             client.SaveXmlCompleted += (sender, args) => HtmlPage.Window.Invoke("DisplayAlertMessage", string.Format("{0}\r\n{1}", args.Error != null ? args.Error.Message : "", args.Cancelled ? "Cancel" : "OK"));
             client.SaveXmlAsync(stringWriter.ToString());
         }
     }
 }
开发者ID:hack2root,项目名称:SilverlightComposer,代码行数:29,代码来源:SaveCommand.cs

示例14: CreateCSVExcel

        /// <summary>
        /// 创建CSV格式的Excel
        /// </summary>
        /// <param name="dt">数据</param>
        /// <param name="fileName">生成的Excel文件名</param>
        /// <param name="titleColumns">Excel标题名称组</param>
        /// <param name="columnNames">数据字段名称组</param>
        /// <param name="columnTypes">数据类型名称组</param>
        public static void CreateCSVExcel(DataTable dt, string fileName, string titleColumns, string columnNames, string columnTypes)
        {
            string[] titleColumnCollection = titleColumns.Split(',');
            string[] columnNameCollection = columnNames.Split(',');
            string[] columnTypeCollection = columnTypes.Split(',');

            if (!
                ((columnNameCollection.Length == columnTypeCollection.Length)
                && (columnNameCollection.Length == titleColumnCollection.Length))
                )
                throw new Exception("Excel设置的数据参数有误");

            HttpResponse resp;
            resp = HttpContext.Current.Response;
            resp.Buffer = true;
            resp.ContentType = "application/vnd.ms-excel";
            resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            resp.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));

            StringWriter sw = new StringWriter();

            sw.WriteLine(titleColumns);

            foreach (DataRow eachRow in dt.Rows)
            {
                sw.WriteLine(GetEachRowExcelData(eachRow, columnNameCollection, columnTypeCollection));
            }
            sw.Close();
            resp.Write(sw);
            resp.End();
        }
开发者ID:steven-han,项目名称:TQuery.Net,代码行数:39,代码来源:ExcelHelper.cs

示例15: ToString

        public override string ToString()
        {
            string doc;

            using (var sw = new StringWriter()) {
                using (var writer = new XmlTextWriter(sw)) {
                    writer.Formatting = Formatting.Indented;
                    //writer.WriteStartDocument();
                    writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
                    writer.WriteStartElement("D", "multistatus", "DAV:");
                    for (int i = 0; i < _nameSpaceList.Count; i++) {
                        string tag = string.Format("ns{0}", i);
                        writer.WriteAttributeString("xmlns", tag, null, _nameSpaceList[i]);
                    }

                    foreach (var oneResponse in _ar) {
                        oneResponse.Xml(writer);
                    }
                    writer.WriteEndElement();
                    //writer.WriteEndDocument();
                    writer.Flush();
                    writer.Close();
                    doc = sw.ToString();
                    writer.Flush();
                    writer.Close();
                }
                sw.Flush();
                sw.Close();
            }
            return doc;
        }
开发者ID:jsakamoto,项目名称:bjd5,代码行数:31,代码来源:PropFindResponce.cs


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