Wednesday, January 23, 2008
Page Log Image & JavaScript Page Processing
We have provided below sample source code for JavaScript Page Processing in Asp.Net. You can copy and paste it in your pages to create the sample application.
Code for Processing Page (PageProcessor.aspx)
scrip
function PageOnLoad()
{
location.href = "<%=PageToLoad%>";
document.images['imgsrc'].src="Images/Loading.gif";
}
script
body bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0" onload="PageOnLoad();"
form id="form1" runat="server"
div
table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%"
tr
td height="50" class="NormalText" align=center valign="bottom"
h3We are processing your request. Please wait.. h3
td
tr
tr
td align="center" height="250" valign="top
img src="" name="imgsrc" td
tr
tab le
di v
Source Code of code-behind file (PageProcessor.aspx.cs)
protected string PageToLoad;
protected void Page_Load(object sender, EventArgs e)
{
PageToLoad = Request.QueryString["PageId"];
}
Code for Processing Page (PageProcessor.aspx)
scrip
function PageOnLoad()
{
location.href = "<%=PageToLoad%>";
document.images['imgsrc'].src="Images/Loading.gif";
}
script
body bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0" onload="PageOnLoad();"
form id="form1" runat="server"
div
table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%"
tr
td height="50" class="NormalText" align=center valign="bottom"
h3We are processing your request. Please wait.. h3
td
tr
tr
td align="center" height="250" valign="top
img src="" name="imgsrc" td
tr
tab le
di v
Source Code of code-behind file (PageProcessor.aspx.cs)
protected string PageToLoad;
protected void Page_Load(object sender, EventArgs e)
{
PageToLoad = Request.QueryString["PageId"];
}
Labels:
ASP.NET
First paragraph of data from sql server
SELECT ID, Body, CHARINDEX(CHAR(13), Body) AS FirstParagraphLen FROM MyTable
or
SELECT ID,SUBSTRING(Body, 1, CHARINDEX(CHAR(13), Body)) AS 'Text'
FROM TableName
Labels:
ASP.NET
Tuesday, January 22, 2008
How to access Cookies from Other web pages
Public Sub DisplayCookies()
'Create a WebRequest to the specified URI.
Dim req As HttpWebRequest = CType(WebRequest.Create("http://werweb.com/whoison.php"), HttpWebRequest)
'Get an empty cookie container.
req.CookieContainer = New CookieContainer
'Send the request and return the response.
Dim resp As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
'Display the cookies.
Dim alertStr As String
alertStr = "Number of Cookies: " & resp.Cookies.Count.ToString() & Environment.NewLine()
alertStr = alertStr & "------------------------------" & Environment.NewLine()
Dim i As Integer
For i = 0 To resp.Cookies.Count - 1
alertStr = alertStr & resp.Cookies(i).Name & "=" & resp.Cookies(i).Value & Environment.NewLine()
Next
MessageBox.Show(alertStr)
'Close the Response.
resp.Close()
End Sub
Labels:
ASP.NET
Create Thumbnail of an image
System.Drawing.Image image = System.Drawing.Image.FromFile("c:\\mypic.jpg");
System.Drawing.Image.GetThumbnailImageAbort tnabort = new System.Drawing.Image.GetThumbnailImageAbort(tnCallback);
System.Drawing.Image tnimage = image.GetThumbnailImage(32, 32, tnabort, IntPtr.Zero);
tnimage.Save("c:\\tnmypic.jpg");
public bool tnCallback()
{
return true;
}
Labels:
ASP.NET
Send Web Page as Email
//Function which convert URL information as string
//Which is used latter to passed as body message.
private String readHtmlPage(string url)
{
String result;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
//Code for sending webpage as email.
private void btnSend_Click(object sender, System.EventArgs e)
{
//URL is converted into string message.
String message=readHtmlPage(txtURL.Text);
String mailServer = "192.168.0.10"; //Change with your mail server address.
try
{
MailMessage Mailer = new MailMessage();
Mailer.From = txtFrom.Text;
Mailer.To = txtTo.Text;
Mailer.Subject = txtSubject.Text;
Mailer.Body = message;
Mailer.BodyFormat = System.Web.Mail.MailFormat.Html;
SmtpMail.Server(mailServer);
SmtpMail.Send(Mailer);
lblResult.Text = "Page successfully sent!";
}
catch(Exception ex)
{
lblResult.Text = "An error occurred: " + ex.ToString();
}
}
Labels:
ASP.NET
Subscribe to:
Posts (Atom)