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


C# StringWriter类代码示例

本文整理汇总了C#中StringWriter的典型用法代码示例。如果您正苦于以下问题:C# StringWriter类的具体用法?C# StringWriter怎么用?C# StringWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Test1

  public void Test1()
  {


    var context = new ControllerContext( HttpContext.Request.RequestContext, new TestController() );

    var result = ViewEngines.Engines.FindView( context, "~/ActionUrlTest/Test1.html", null );

    Assert.NotNull( result.View, "找不到视图" );


    IHtmlDocument document;

    using ( var writer = new StringWriter() )
    {
      result.View.Render( new ViewContext( context, result.View, new ViewDataDictionary(), new TempDataDictionary(), writer ), writer );

      document = new JumonyParser().Parse( writer.ToString() );
    }


    var link = document.FindFirst( "a" );

    Assert.NotNull( link );

    Assert.AreEqual( link.Attribute( "href" ).Value(), "/TestController/TestAction?arg=args" );


  }
开发者ID:ajayumi,项目名称:Jumony,代码行数:29,代码来源:ActionUrlTest.cs

示例2: CreateStatusText

	private string CreateStatusText()
	{
		using (var sw = new StringWriter())
		using (var jsonWriter = new JsonTextWriter(sw))
		{
			jsonWriter.WriteStartObject();
			{
				// Login
				jsonWriter.WritePropertyName("login");
				jsonWriter.WriteStartObject();
				{
					jsonWriter.WritePropertyName("port");
					jsonWriter.WriteValue(LoginServer.Instance.Conf.Login.Port);
				}
				jsonWriter.WriteEndObject();

				// Servers
				jsonWriter.WritePropertyName("servers");
				jsonWriter.WriteStartObject();
				{
					foreach (var server in LoginServer.Instance.ServerList.List)
					{
						// Channels
						jsonWriter.WritePropertyName(server.Name);
						jsonWriter.WriteStartObject();
						{
							foreach (var channel in server.Channels)
							{
								// Channel
								jsonWriter.WritePropertyName(channel.Key);
								jsonWriter.WriteStartObject();
								{
									jsonWriter.WritePropertyName("host");
									jsonWriter.WriteValue(channel.Value.Host);

									jsonWriter.WritePropertyName("port");
									jsonWriter.WriteValue(channel.Value.Port);

									jsonWriter.WritePropertyName("online");
									jsonWriter.WriteValue(channel.Value.Users);

									jsonWriter.WritePropertyName("onlineMax");
									jsonWriter.WriteValue(channel.Value.MaxUsers);

									jsonWriter.WritePropertyName("state");
									jsonWriter.WriteValue(channel.Value.State);
								}
								jsonWriter.WriteEndObject();
							}
						}
						jsonWriter.WriteEndObject();
					}
				}
				jsonWriter.WriteEndObject();
			}
			jsonWriter.WriteEndObject();

			return sw.ToString();
		}
	}
开发者ID:aura-project,项目名称:aura,代码行数:60,代码来源:status.cs

示例3: PrintWebControl

 public static void PrintWebControl(Control ctrl, string Script)
 {
     StringWriter stringWrite = new StringWriter();
     System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
     if (ctrl is WebControl)
     {
         Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
     }
     Page pg = new Page();
     pg.EnableEventValidation = false;
     if (Script != string.Empty)
     {
         pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
     }
     HtmlForm frm = new HtmlForm();
     pg.Controls.Add(frm);
     frm.Attributes.Add("runat", "server");
     frm.Controls.Add(ctrl);
     pg.DesignerInitialize();
     pg.RenderControl(htmlWrite);
     string strHTML = stringWrite.ToString();
     HttpContext.Current.Response.Clear();
     HttpContext.Current.Response.Write(strHTML);
     HttpContext.Current.Response.Write("<script>window.print();</script>");
     HttpContext.Current.Response.End();
 }
开发者ID:baotiit,项目名称:savvyplatform,代码行数:26,代码来源:PrintHelper.cs

示例4: Export

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sw"></param>
    public static void Export(StringWriter sw, GridView gv)
    {
        using (HtmlTextWriter htw = new HtmlTextWriter(sw))
        {
            //  Create a table to contain the grid
            Table table = new Table();

            //  include the gridline settings
            table.GridLines = gv.GridLines;

            //  add the header row to the table
            if (gv.HeaderRow != null)
            {

                table.Rows.Add(gv.HeaderRow);
            }

            //  add each of the data rows to the table
            foreach (GridViewRow row in gv.Rows)
            {

                table.Rows.Add(row);
            }

            //  add the footer row to the table
            if (gv.FooterRow != null)
            {

                table.Rows.Add(gv.FooterRow);
            }

            //  render the table into the htmlwriter
            table.RenderControl(htw);
        }
    }
开发者ID:manivts,项目名称:impexcubeapp,代码行数:39,代码来源:NewExportGridViewToExcelClass.cs

示例5: btnExcel_Click

 protected void btnExcel_Click(object sender, EventArgs e)
 {
     try
     {
         ChangeControlsToValue(gvDeposits);
        // gvDeposits.Columns[13].Visible = false;
         Response.ClearContent();
         Response.AddHeader("content-disposition", "attachment; filename=AgentDeposits.xls");
         Response.ContentType = "application/excel";
         StringWriter sWriter = new StringWriter();
         HtmlTextWriter hTextWriter = new HtmlTextWriter(sWriter);
         HtmlForm hForm = new HtmlForm();
         gvDeposits.Parent.Controls.Add(hForm);
         hForm.Attributes["runat"] = "server";
         hForm.Controls.Add(gvDeposits);
         hForm.RenderControl(hTextWriter);
         StringBuilder sBuilder = new StringBuilder();
         sBuilder.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"> <head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>ExportToExcel</x:Name><x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head> <body>");
         sBuilder.Append(sWriter + "</body></html>");
         Response.Write(sBuilder.ToString());
         Response.End();
         //gvDeposits.Columns[13].Visible = true;
     }
     catch (Exception ex)
     {
         //lblMsg.InnerHtml = ex.Message;
         throw ex;
     }
 }
开发者ID:srisai339,项目名称:LoveJourney_Working,代码行数:29,代码来源:frmAgentsDeposits.aspx.cs

示例6: GetDeliveries

 internal static string GetDeliveries()
 {
     sql = "SELECT " +
             "deliveries.id AS delivery_id, purchases.id AS purchase_id, purchases.po_number, deliveries.delivery_date, supplier_id, name AS supplier_name, " +
             "lookup_status.description AS status, lookup_status2.description AS completion_status " +
         "FROM deliveries " +
         "JOIN purchases ON purchases.id = deliveries.purchase_id " +
         "JOIN suppliers ON suppliers.id = supplier_id " +
         "JOIN lookup_status ON lookup_status.id = deliveries.status " +
         "JOIN lookup_status AS lookup_status2 ON lookup_status2.id = deliveries.completion_status " +
         "WHERE lookup_status2.description != 'Complete' ";
     dt = new DataTable();
     dt = Database.Query(sql);
     if (dt != null)
     {
         if (dt.Rows[0].ItemArray[0].ToString() == "-1")
         {
             result = dt.Rows[0].ItemArray[1].ToString();
         }
         else
         {
             StringWriter sw = new StringWriter();
             dt.WriteXml(sw);
             result = sw.ToString();
         }
     }
     else
     {
         result = Functions.FormatReturn(0, "No items found");
     }
     return result;
 }
开发者ID:kingpauloaquino,项目名称:CERP-WS,代码行数:32,代码来源:Queries.cs

示例7: DataTableToJSON

    public static string DataTableToJSON(DataTable dt, string dtName)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);

        //using (JsonWriter jw = new JsonWriter(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();
    }
开发者ID:guyuefeng,项目名称:aspnet-sample,代码行数:33,代码来源:JsonHelper.cs

示例8: TestGraphConnectedComponents9Vertices

    public void TestGraphConnectedComponents9Vertices()
    {
        // Arrange
        var input =
            "9" + "\n" +
            "3 6" + "\n" +
            "3 4 5 6" + "\n" +
            "8" + "\n" +
            "0 1 5" + "\n" +
            "1 6" + "\n" +
            "1 3" + "\n" +
            "0 1 4" + "\n" +
            string.Empty + "\n" +
            "2" + "\n";

        // Act
        var inputReader = new StringReader(input);
        var outputWriter = new StringWriter();
        using (outputWriter)
        {
            Console.SetIn(inputReader);
            Console.SetOut(outputWriter);
            GraphConnectedComponents.Main();
        }

        var output = outputWriter.ToString();

        // Assert
        var expectedOutput = 
            "Connected component: 6 4 5 1 3 0" + "\n" +
            "Connected component: 8 2" + "\n" +
            "Connected component: 7" + "\n";
        output = output.Replace("\r\n", "\n");
        Assert.AreEqual(expectedOutput, output);
    }
开发者ID:nok32,项目名称:SoftUni,代码行数:35,代码来源:UnitTestsGraph.cs

示例9: btnExport2Excel_Click

    protected void btnExport2Excel_Click(object sender, EventArgs e)
    {
        Response.ClearContent();
        Response.AppendHeader("content-disposition", "attachment; filename=Evaluation Report between " + txtStartDate.Text + " and " + txtEndDate.Text + ".xls");
        Response.ContentType = "application/excel";

        StringWriter stringWrite = new StringWriter();
        HtmlTextWriter htmlTextWrite = new HtmlTextWriter(stringWrite);

        GridView2.HeaderRow.Style.Add("background-color", "#FFFFFF");
        foreach (TableCell tableCell in GridView2.HeaderRow.Cells)
        {
            tableCell.Style["background-color"] = "#5D7B9D";
        }

        foreach (GridViewRow gridViewRow in GridView2.Rows)
        {
            gridViewRow.BackColor = System.Drawing.Color.White;
            foreach (TableCell gridViewRowTableCell in gridViewRow.Cells)
            {
                gridViewRowTableCell.Style["background-color"] = "#F7F6F3";
            }
        }

        GridView2.RenderControl(htmlTextWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
    }
开发者ID:jLeta,项目名称:HN_HR_1.0,代码行数:28,代码来源:Evaluation.aspx.cs

示例10: Button2_Click

    protected void Button2_Click(object sender, EventArgs e)
    {
        string flytype = ddlflyertype.SelectedItem.Text;
        string flysize = ddlflyersize.SelectedItem.Text;
        string flyptype = ddlptype.SelectedItem.Text;
        string flypsize = ddlpsize.SelectedItem.Text;
        string flypapertype = ddlpapertype.SelectedItem.Text;
        string flypaperthkness = ddlpaperthkness.SelectedItem.Text;

        string email = txtemail.Text;

        string To = ConfigurationManager.AppSettings["To"].ToString();
        string from = txtemail.Text;
        string website = ConfigurationManager.AppSettings["WebSite"].ToString();
        string displayname = ConfigurationManager.AppSettings["displayname"].ToString();
        string subject = "Thank you for Inquiry from " + website;
        string thankyoumessage = "Thank you for Inquiry with " + displayname + ".";
        TextWriter txtWriter = new StringWriter() as TextWriter;

        Server.Execute("~/MailTemplete/flyer.aspx?&thankyoumessage=" + thankyoumessage + "&flytype=" + flytype + "&flysize=" + flysize + "&flyptype=" + flyptype + "&flypsize=" + flypsize + "&flypapertype=" + flypapertype + "&flypaperthkness=" + flypaperthkness + "&email=" + email, txtWriter);
           // string attachment = Request.PhysicalApplicationPath + @"\userfiles\resume\" + resume;
        Response.Write(txtWriter);
        Response.End();

        try
        {
            Utilities.SendAttachMail(from, To, subject, txtWriter.ToString());
        }
        catch (Exception ex)
        {
        }
           // reset();
           Response.Redirect("~/thankyou.aspx");
    }
开发者ID:harshitshah436,项目名称:web-development,代码行数:34,代码来源:Design+and+Print.aspx.cs

示例11: TestGraphConnectedComponents1Vertex

    public void TestGraphConnectedComponents1Vertex()
    {
        // Arrange
        var input =
            "1" + "\n" +
            "0" + "\n";

        // Act
        var inputReader = new StringReader(input);
        var outputWriter = new StringWriter();
        using (outputWriter)
        {
            Console.SetIn(inputReader);
            Console.SetOut(outputWriter);
            GraphConnectedComponents.Main();
        }

        var output = outputWriter.ToString();

        // Assert
        var expectedOutput =
            "Connected component: 0\n";
        output = output.Replace("\r\n", "\n");
        Assert.AreEqual(expectedOutput, output);
    }
开发者ID:nok32,项目名称:SoftUni,代码行数:25,代码来源:UnitTestsGraph.cs

示例12: btnPDF_Click

 protected void btnPDF_Click(object sender, ImageClickEventArgs e)
 {
     Response.ContentType = "application/pdf";
     Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
     StringWriter sw = new StringWriter();
     HtmlTextWriter hw = new HtmlTextWriter(sw);
     gvdetails.AllowPaging = false;
     gvdetails.DataBind();
     gvdetails.RenderControl(hw);
     gvdetails.HeaderRow.Style.Add("width", "15%");
     gvdetails.HeaderRow.Style.Add("font-size", "10px");
     gvdetails.Style.Add("text-decoration", "none");
     gvdetails.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
     gvdetails.Style.Add("font-size", "8px");
     StringReader sr = new StringReader(sw.ToString());
     Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
     HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
     PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
     pdfDoc.Open();
     htmlparser.Parse(sr);
     pdfDoc.Close();
     Response.Write(pdfDoc);
     Response.End();
 }
开发者ID:dineshkummarc,项目名称:DataExportusingDotNet,代码行数:25,代码来源:Default.aspx.cs

示例13: btnExport_Click

    protected void btnExport_Click(object sender, EventArgs e)
    {
        using (StringWriter sw = new StringWriter())
        {
            using (HtmlTextWriter hw = new HtmlTextWriter(sw))
            {
                //To Export all pages
                grid_monthly_attendanceDetailed.AllowPaging = false;
                //this.BindGrid();

                grid_monthly_attendanceDetailed.RenderBeginTag(hw);
                grid_monthly_attendanceDetailed.HeaderRow.RenderControl(hw);
                foreach (GridViewRow row in grid_monthly_attendanceDetailed.Rows)
                {
                    row.RenderControl(hw);
                }
                grid_monthly_attendanceDetailed.FooterRow.RenderControl(hw);
                grid_monthly_attendanceDetailed.RenderEndTag(hw);
                StringReader sr = new StringReader(sw.ToString());
                Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
                HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();

                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=Report.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Write(pdfDoc);
                Response.End();
            }
        }
    }
开发者ID:hmandal,项目名称:BiometricsAttendanceSystem,代码行数:34,代码来源:MonthlyAttendanceEmployeeWise.aspx.cs

示例14: Main

	static int Main ()
	{
		TinyHost h = CreateHost ();
		StringWriter sw = new StringWriter ();
		h.Execute ("Default.aspx", sw);
		string result = sw.ToString ();
#if ONLY_1_1 && !MONO
		if (result.IndexOf ("<option value=\"1\">janvier</option>") == -1) {
#else
		if (result.IndexOf ("<option value=\"1\" title=\"tooltip of 1\">janvier</option>") == -1) {
#endif
			Console.WriteLine (result);
			return 1;
		}
#if ONLY_1_1 && !MONO
		if (result.IndexOf ("<option value=\"12\">d&#233;cembre</option>") == -1) {
#else
		if (result.IndexOf ("<option value=\"12\" title=\"tooltip of 12\">d&#233;cembre</option>") == -1) {
#endif
			Console.WriteLine (result);
			return 2;
		}
		return 0;
	}
}
开发者ID:mono,项目名称:gert,代码行数:25,代码来源:test.cs

示例15: Main

	public static void Main(string[] arg) {
		if (arg.Length < 1) throw new ArgumentException("Must pass one or two command line arguments.");
	
		StringWriter sw = new StringWriter();
		string s;
		while ((s = Console.ReadLine()) != null) {
			sw.WriteLine(s);
		}
		
		XmlDocument d = new XmlDocument();
		d.LoadXml(sw.ToString());
		
		object ret;
		
		if (arg.Length == 1) {
			ret = d.CreateNavigator().Evaluate(arg[0]);
		} else if (arg.Length == 2 && arg[0] == "-expr") {
			ret = d.CreateNavigator().Evaluate(arg[1]);
		} else if (arg.Length == 2 && arg[0] == "-node") {
			ret = d.SelectSingleNode(arg[1]);
		} else {
			throw new ArgumentException("Bad command line arguments.");
		}
		
		if (ret is XPathNodeIterator) {
			XPathNodeIterator iter = (XPathNodeIterator)ret;
			while (iter.MoveNext()) {
				Console.WriteLine(iter.Current);
			}
		} else if (ret is XmlNode) {
			Console.WriteLine(((XmlNode)ret).InnerXml);
		} else {
			Console.WriteLine(ret);
		}
	}
开发者ID:emtees,项目名称:old-code,代码行数:35,代码来源:xpath.cs


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