Thursday, September 2, 2010

How to Append Image path to Text File using C#

by Emmaneale Mendu, Web Developer

.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Image Button Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

</div>
</form>
</body>
</html>

.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
String FileName = Server.MapPath("Output.txt");

StreamWriter objStreamWriter;
objStreamWriter = File.AppendText(FileName);

String imagepath = Html32TextWriter.DoubleQuoteChar + "desibindaas.jpg"
+ Html32TextWriter.DoubleQuoteChar;

objStreamWriter.WriteLine("<img src=" + imagepath + " alt=" + Html32TextWriter.DoubleQuoteChar
+ "Emmu Image" + Html32TextWriter.DoubleQuoteChar + " /><br/>");

objStreamWriter.Close();

StreamReader objStreamReader;
objStreamReader = File.OpenText(FileName);

String contents = objStreamReader.ReadToEnd();
Response.Write(contents);
objStreamReader.Close();
}
}

3 comments:

Unknown said...

Why here is not any explaination...........please add content that explains it...

technoramayan.blogspot.com

or explain me on

vishal51190@gmail.com

thankssssssss in advance

Safia Jilani said...

Nice

Ronnie Billum said...

I really appreciated your blog post about learning ASP.Net tutorials. I don't know much about ASP, but I enjoyed reading your post. It had great tips and tricks and I liked the fact that it was a Thursday, September 2, 2010. I read your blog post in the morning, and by the evening I was ready to try out a few of the tips you talked about! Learn .NET

Post a Comment

Related Posts with Thumbnails