本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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";
}
示例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());
}
}
}
示例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();
}
示例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;
}