本文整理汇总了C#中StringWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.Close方法的具体用法?C# StringWriter.Close怎么用?C# StringWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringWriter
的用法示例。
在下文中一共展示了StringWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToXml
public string ToXml()
{
XmlSerializer xmls = new XmlSerializer(typeof(User));
StringWriter writer = new StringWriter();
xmls.Serialize(writer, this);
writer.Close();
return writer.ToString();
}
示例2: DataTableToJSON
public static string DataTableToJSON(DataTable dt, string dtName)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jw = new JsonTextWriter(sw))
{
JsonSerializer ser = new JsonSerializer();
jw.WriteStartObject();
jw.WritePropertyName(dtName);
jw.WriteStartArray();
foreach (DataRow dr in dt.Rows)
{
jw.WriteStartObject();
foreach (DataColumn dc in dt.Columns)
{
jw.WritePropertyName(dc.ColumnName);
ser.Serialize(jw, dr[dc].ToString());
}
jw.WriteEndObject();
}
jw.WriteEndArray();
jw.WriteEndObject();
sw.Close();
jw.Close();
}
return sb.ToString();
}
示例3: SavePref
public void SavePref()
{
var mySeriData = new XmlSerializer(typeof(PlayerPrefsSerializer));
StringWriter Writer = new StringWriter();
mySeriData.Serialize(Writer, this);
string tmp = Writer.ToString();
PlayerPrefs.SetString(key, tmp);
Writer.Close();
}
示例4: serialization
// Use this for initialization
public static string serialization(object o)
{
string text="";
TextWriter writer;
XmlSerializer serialWrite = new XmlSerializer (o.GetType());
writer = new StringWriter();
serialWrite.Serialize (writer, o);
text=writer.ToString();
writer.Close ();
return text;
}
示例5: btnExport_Click
protected void btnExport_Click(object sender, EventArgs e)
{
string style = @"<style> .text { mso-number-format:\@; } </script> ";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.GridView2.RenderControl(htw);
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=test.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(style);
Response.Write(sw);
Response.End();
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string m = "<?xml version=\"1.0\"?>";
m += "<address>";
m += "<addressline1>" + "Veerannapet" + "</addressline1>";
m += "<addressline2>" + "Veerannapet2" + "</addressline2>";
m += "<city>" + "Mahabubnagar" + "</city>";
m += "<postcode>" + "509001" + "</postcode>";
m += "</address>";
string result1 = m.Replace("<?xml version=\"1.0\"?>", "");
XmlDocument docs = new XmlDocument();
docs.LoadXml(result1);
string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(docs);
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json, "Report");
XslCompiledTransform xsl = new XslCompiledTransform();
StringWriter result = new StringWriter();
xsl.Load(Server.MapPath("Focus.xslt"));
XmlTextWriter tx = new XmlTextWriter(result);
XmlDeclaration xmldecl;
xmldecl = doc.CreateXmlDeclaration("1.0", null, null);
XmlElement root = doc.DocumentElement;
doc.InsertBefore(xmldecl, root);
//string strs = doc.InnerXml.ToString();
doc.WriteTo(tx);
xsl.Transform(doc, null, tx);
result.Close();
result.Flush();
string str = result.ToString();
// ... And the result you'll send back will be usable in a report:
Response.ContentType = "text/xml";
Response.Write(str.ToString());
Response.Flush();
Response.Close();
}
示例7: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string searchWords = Request.QueryString["SearchWords"];
string indexNames = Request.QueryString["IndexNames"];
//Response.Write(searchWords);
string hostname = ConfigurationManager.AppSettings["HostName"];
int port = int.Parse(ConfigurationManager.AppSettings["PortNum"]);
TcpClient client;
NetworkStream ns;
BinaryFormatter formater;
DateTime now = DateTime.Now;
try
{
client = new TcpClient(hostname, port);
ns = client.GetStream();
formater = new BinaryFormatter();
SearchInfo sinfo = new SearchInfo();
QueryInfo info = new QueryInfo();
info.IndexNames = "";
info.SearchWords = searchWords;
info.IndexNames = indexNames;
sinfo.Query = info;
sinfo.PageSize = 10;
formater.Serialize(ns, sinfo);
SearchResult sr = (SearchResult)formater.Deserialize(ns);
//WriteLog(Server.MapPath(".") + "searchutils.log", searchWords, indexNames, sr.Records.Count, sr);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(SearchResult));
StringBuilder builder = new StringBuilder();
StringWriter writer = new StringWriter(builder);
xmlSerializer.Serialize(writer, sr);
XmlDocument doc = new XmlDocument();
doc.LoadXml(builder.ToString());
writer.Close();
ns.Close();
Response.Write(doc.DocumentElement.OuterXml);
//FileStream fs = new FileStream(@"result.xml", FileMode.Truncate);
//xmlSerializer.Serialize(writer, fs);
//fs.Close();
}
catch (Exception se)
{
Response.Write(se.StackTrace.ToString());
return;
}
}
示例8: ParseResponse
private void ParseResponse(string response)
{
XmlDocument doc = null;
XslTransform myXslTransform = null;
StringWriter sw = null;
try
{
doc = new XmlDocument(); ;
myXslTransform = new XslTransform();
sw = new StringWriter();
doc.LoadXml(response);
myXslTransform.Load("C:\\Users\\simona.EDUSOFT2\\Documents\\Visual Studio 2013\\WebSites\\WebSite1\\transform.xsl");
myXslTransform.Transform(doc, null, sw);
string result = sw.ToString().Replace("xmlns:asp=\"remove\"",
"").Replace("<", "<").Replace(">", ">");
Control control = Page.FindControl("MyTable");
if (control != null)
{
Page.Controls.Remove(control);
}
Control ctrl = Page.ParseControl(result);
Page.Controls.Add(ctrl);
MyPanel.Visible = false;
}
catch
{
//parsing or loading error
displayErrorMessage(errorParsingOrLoading);
}
finally
{
sw.Close();
}
}
示例9: DownloadAsExcel
/// <summary>
///操作DataGrid DataTable導出到Excel.繁體OS,無亂碼問題.
/// </summary>
/// <param name="dg">DataTable</param>
/// <param name="ckID">CheckBox项的ID值 cbMail</param>
/// <param name="strFileName">含.xls後綴</param>
public static void DownloadAsExcel(DataGrid dg, DataSet ds, string ckID, string strFileName)
{
DataTable dt = GetSelectedTable(dg, ckID, ds);
if (dt == null)
{
dt = new DataTable();
}
try
{
StringWriter sw = new StringWriter();
string colstr = "";
foreach (DataColumn col in dt.Columns)
{
colstr += col.ColumnName + "\t";
}
sw.WriteLine(colstr);
foreach (DataRow row in dt.Rows)
{
colstr = "";
foreach (DataColumn col in dt.Columns)
{
colstr += row[col.ColumnName].ToString() + "\t";
}
sw.WriteLine(colstr);
}
sw.Close();
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName + "");
System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
System.Web.HttpContext.Current.Response.Write(sw);
System.Web.HttpContext.Current.Response.End();
}
catch (Exception ex)
{
}
}
示例10: printbutton_Click
protected void printbutton_Click(object sender, EventArgs e)
{
// Create a Document object
Document document = new Document();
string contents = string.Empty;
//string contents = File.ReadAllText(Server.MapPath("~/pdftest.html"));
//string css = File.ReadAllText(Server.MapPath("~/Content/Site.css"));
MemoryStream ms = new MemoryStream();
using (StringWriter sw = new StringWriter()) {
Server.Execute("pdf.aspx", sw);
contents = sw.ToString();
sw.Close();
}
//ICSSResolver resolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(true);
//string css = Server.MapPath("~/Content/Site.css");
//resolver.AddCssFile(css, true);
}
示例11: btnExport_Click
//.........这里部分代码省略.........
sbText = AppendCSVFields(sbText, "VXCCBB");
//ȥ��β���Ķ���
sbText.Remove(sbText.Length - 1, 1);
//дdatatable��һ��
swCSV.WriteLine(sbText.ToString());
//����datatable��������
foreach (DataRow drTemp in tbVendorView.Rows) {
sbText = new StringBuilder();
sbText = AppendCSVFields(sbText, drTemp["VNSTAT"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMID"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VENDOR"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VNDNAM"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VNDAD1"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VNDAD2"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VCITY"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VSTATE"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPOST"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VTERMS"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VTYPE"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPAYTO"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VDTLPD"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VDAYCL"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VGL"].ToString());
sbText = AppendCSVFields(sbText, drTemp["V1099"].ToString());
sbText = AppendCSVFields(sbText, drTemp["V1099C"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPHONE"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VCMPNY"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VCURR"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPAYTY"].ToString());
sbText = AppendCSVFields(sbText, drTemp["V1TIME"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VCORPV"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VHOLD"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VHOLDT"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPYTYR"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VDSCAV"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VDSCTK"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VDPURS"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VNNEXT"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VNGEN"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VNALPH"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VNUNAL"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VCON"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VCOUN"].ToString());
sbText = AppendCSVFields(sbText, drTemp["V1099S"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPAD1"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPAD2"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPCTY"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPSTE"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPPST"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPCON"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPCOU"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMFRM"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMMAT"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VTAX"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VPPHN"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMFSCD"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMIDNM"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VTAXCD"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMXNBR"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMXCRT"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMXDTE"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMXMAX"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VFOB"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMCLAS"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMRATE"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMDCPX"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMSRCC"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMSRNO"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMPREQ"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VMID"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXNUMB"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXCUR"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXBKCD"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXTYP"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXBNKN"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXACT"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXB2BA"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXCCB"].ToString());
sbText = AppendCSVFields(sbText, drTemp["VXCCBB"].ToString());
//ȥ��β���Ķ���
sbText.Remove(sbText.Length - 1, 1);
//дdatatable��һ��
swCSV.WriteLine(sbText.ToString());
}
//�����ļ�
DownloadFile(Response, swCSV.GetStringBuilder(), "Vendor_Export_" + DateTime.Now.ToString("yyyyMMdd") + ".csv");
swCSV.Close();
Response.End();
} catch (Exception ex) {
throw ex;
}
}
示例12: Export_with_XSLT_Windows
// Function : Export_with_XSLT_Windows
// Arguments : dsExport, sHeaders, sFileds, FormatType, FileName
// Purpose : Exports dataset into CSV / Excel format
private void Export_with_XSLT_Windows(DataSet dsExport, string[] sHeaders, string[] sFileds, ExportFormat FormatType, string FileName)
{
try
{
// XSLT to use for transforming this dataset.
MemoryStream stream = new MemoryStream( );
XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
CreateStylesheet(writer, sHeaders, sFileds, FormatType);
writer.Flush( );
stream.Seek( 0, SeekOrigin.Begin);
XmlDocument xsl = new XmlDocument();
xsl.Load(stream);
//XslTransform xslTran = new XslTransform();
//xslTran.Load(new XmlTextReader(stream), null, null);
//System.IO.StringWriter sw = new System.IO.StringWriter();
//xslTran.Transform(xmlDoc, null, sw, null);
XmlDataDocument xmlDoc = new XmlDataDocument(dsExport);
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
XslCompiledTransform t = new XslCompiledTransform();
t.Load((IXPathNavigable)xsl, null, null);
t.Transform((IXPathNavigable)xmlDoc, xtw);
//Writeout the Content
File.WriteAllText(FileName, sw.ToString());
sw.Close();
xtw.Close();
writer.Close();
stream.Close();
sw.Dispose();
stream.Dispose();
}
catch(Exception Ex)
{
throw Ex;
}
}
示例13: GenerateCode
private static string GenerateCode(string expression)
{
var source = new StringBuilder();
var sw = new StringWriter(source);
var options = new CodeGeneratorOptions();
var myNamespace = new CodeNamespace("ExpressionEvaluator");
myNamespace.Imports.Add(new CodeNamespaceImport("System"));
var classDeclaration = new CodeTypeDeclaration { IsClass = true, Name = "Calculator", Attributes = MemberAttributes.Public };
var myMethod = new CodeMemberMethod { Name = "Calculate", ReturnType = new CodeTypeReference(typeof(double)), Attributes = MemberAttributes.Public };
myMethod.Statements.Add(new CodeMethodReturnStatement(new CodeSnippetExpression(expression)));
classDeclaration.Members.Add(myMethod);
myNamespace.Types.Add(classDeclaration);
provider.GenerateCodeFromNamespace(myNamespace, sw, options);
sw.Flush();
sw.Close();
return source.ToString();
}
示例14: ConvertToXml
public static string ConvertToXml(object toSerialize, Type objectType)
{
// create a string wrtiter to hold the xml string
// the a xml writer with the proper settings.
// use that writer to serialize the document.
// use an namespace to create a fully qualified odcument.
StringWriter aWriter = new StringWriter();
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Document; // Fragment fails
settings.Indent = false;
settings.Encoding = System.Text.Encoding.UTF8;
XmlWriter xWriter = XmlWriter.Create(aWriter, settings);
new XmlSerializerNamespaces();
XmlSerializerNamespaces myNamespaces = new XmlSerializerNamespaces();
myNamespaces.Add("wtr", "http://www.cuahsi.org/waterML/1_1/");
myNamespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
myNamespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
myNamespaces.Add("gml", "http://www.opengis.net/gml");
myNamespaces.Add("xlink", "http://www.w3.org/1999/xlink");
myNamespaces.Add("xml", "http://www.w3.org/XML/1998/namespace");
XmlSerializer aSerializer = new XmlSerializer(objectType);
//aSerialize(xWriter, toSerialize);
aSerializer.Serialize(xWriter, toSerialize, myNamespaces);
string xml = aWriter.ToString();
aWriter.Flush();
aWriter.Close();
return xml;
}
示例15: Export_with_XSLT_Web
// Function : Export_with_XSLT_Web
// Arguments : dsExport, sHeaders, sFileds, FormatType, FileName
// Purpose : Exports dataset into CSV / Excel format
private void Export_with_XSLT_Web(DataSet dsExport, string[] sHeaders, string[] sFileds, ExportFormat FormatType, string FileName)
{
try
{
// Appending Headers
response.Clear();
response.Buffer= true;
if(FormatType == ExportFormat.CSV)
{
response.ContentType = "text/csv";
response.AppendHeader("content-disposition", "attachment; filename=" + FileName);
}
else
{
response.ContentType = "application/vnd.ms-excel";
response.AppendHeader("content-disposition", "attachment; filename=" + FileName);
}
// XSLT to use for transforming this dataset.
MemoryStream stream = new MemoryStream( );
XmlTextWriter writer = new XmlTextWriter(stream, Encoding.Default);
CreateStylesheet(writer, sHeaders, sFileds, FormatType);
writer.Flush( );
stream.Seek( 0, SeekOrigin.Begin);
XmlDocument xsl = new XmlDocument();
xsl.Load(stream);
//XslTransform xslTran = new XslTransform();
//xslTran.Load(new XmlTextReader(stream), null, null);
//System.IO.StringWriter sw = new System.IO.StringWriter();
//xslTran.Transform(xmlDoc, null, sw, null);
XmlDataDocument xmlDoc = new XmlDataDocument(dsExport);
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
XslCompiledTransform t = new XslCompiledTransform();
t.Load((IXPathNavigable)xsl, null, null);
t.Transform((IXPathNavigable)xmlDoc, xtw);
//Writeout the Content
response.Write(sw.ToString());
sw.Close();
xtw.Close();
writer.Close();
stream.Close();
response.End();
sw.Dispose();
stream.Dispose();
}
catch(ThreadAbortException Ex)
{
string ErrMsg = Ex.Message;
}
catch(Exception Ex)
{
throw Ex;
}
}