Thursday, January 22, 2009

Image resize using GetThumbnailImage Function

Image resize using .GetThumbnailImage Function
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO.Compression;
using System.Drawing.Drawing2D;


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

Image thumbnailImage;
Bitmap originalImage;

originalImage = new Bitmap("E:\\Retreat.jpg");
int imgHeight = originalImage.Height;
int imgWidht = originalImage.Width;
string format = Convert.ToString(originalImage.RawFormat);
ImageFormat imageFormat;

switch (format)
{
case ("gif"):
imageFormat = ImageFormat.Gif;
break;
default:
imageFormat = ImageFormat.Jpeg;
format = "jpg";
break;
}

if (imgWidht == 0)
{ imgWidht = 100; }

if (imgHeight == 0)
{ imgHeight = imgWidht; }

string ImageSavePath = "E:\\jj1234.jpg";
thumbnailImage = originalImage.GetThumbnailImage(imgWidht, imgHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailImageAbortDelegate), IntPtr.Zero);
thumbnailImage.Save(ImageSavePath, imageFormat);
originalImage.Dispose();
}
protected static bool ThumbnailImageAbortDelegate() { return false; }
}


ASP.NET Resize images proportionately

ASP.NET Resize images proportionately
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO.Compression;
using System.Drawing.Drawing2D;


public partial class ImageResize : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string ImageSavePath = "E:\\jj1.jpg";
string BasePath = Server.MapPath(".");
Bitmap Img, ImgTemp;

ImgTemp = new Bitmap("E:\\Retreat.jpg");
int imgHeight = ImgTemp.Height;
int imgWidht = ImgTemp.Width;

Img = new Bitmap(ImgTemp,imgWidht*40/100, imgHeight*30/100);
Img.Save(ImageSavePath, ImageFormat.Jpeg);

ImgTemp.Dispose();
Img.Dispose();

//Graphics Graph;
//Graph = Graphics.FromImage(Img);
//Graph.DrawImage(Img, 100, 100);

}
}

Monday, January 12, 2009

ASP.NET C# Using Session variables in a class files .cs app_code

ASP.NET C# Using Session variables in a class files .cs app_code


Use HttpContext.Current.Session

VB.NET


HttpContext.Current.Session("Value1") = "1"

C#

HttpContext.Current.Session["Value1"] = "1";

HttpSession session = HttpContext.Current.Session;

session["key"] = "test";

HttpSession doesn't exist , i think we must use HttpSessionState

System.Web.SessionState.HttpSessionState session = HttpContext.Current.Session;

session["key"] = "test";


More on Session :: http://www.syncfusion.com/faq/aspnet/web_c9c.aspx#q179q

Thursday, January 01, 2009

ASP.NET: Calendar Control DayRender

ASP.NET: Calendar Control DayRender Sample Code
Method 1

Method 2Code Sample:

.cs page
DataSet ds = new DataSet();
protected void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["DBConnStr"]);
string sql = "select eventid,eventdt,title1 from calendar";
OleDbDataAdapter da = new OleDbDataAdapter(sql, myConnection);
da.Fill(ds, "events");
}
protected void eventscalendar_DayRender(Object Src, DayRenderEventArgs E)
{
int i = 0;
StringBuilder strEvents = new StringBuilder();
strEvents.Append("");
foreach (DataRow row in ds.Tables["events"].Rows)
{
DateTime eventdate = (DateTime)row["eventdt"];
if (eventdate.Equals(E.Day.Date))
{
i++;
strEvents.Append("
" + row["title1"]);
strEvents.Append("
");
}
}
if (i > 0)
{
if (E.Day.Date != DateTime.Now.Date)
{
E.Cell.BackColor = Color.AliceBlue;
}
// strEvents.Append("
Events: " + i + "");
}
E.Cell.Controls.Add(new LiteralControl(strEvents.ToString()));
}

protected void eventcalendar_SelectionChanged(object sender, EventArgs e)
{
DataSet ds1 = new DataSet();
DateTime dt = eventcalendar.SelectedDate.Date;
OleDbConnection myConnection = new OleDbConnection(ConfigurationSettings.AppSettings["DBConnStr"]);
string sql = "select starttime,endtime,title1,description from calendar where eventdt='" + dt + "'";

OleDbDataAdapter da = new OleDbDataAdapter(sql, myConnection);
da.Fill(ds1, "events");
GridView1.DataSource = ds1;
GridView1.DataBind();
}


.aspx page:
<asp:calendar id="eventcalendar" TitleStyle-BackColor="#d18c25" NextPrevStyle-ForeColor="#ffffff" TitleStyle-Height="30px" ShowGridLines="true" runat="server" backcolor="white"
width="400px" height="400px" font-size="12px"
nextprevformat="ShortMonth" daynameformat="FirstTwoLetters"
firstdayofweek="Sunday" OnDayRender="eventscalendar_DayRender" OnSelectionChanged="eventcalendar_SelectionChanged">
<DayStyle Font-Names="TimesRoman" />
<SelectedDayStyle Font-Names="TimesRoman" Height="20px" Width="20px" Font-Size="11px" ForeColor="#680000" BackColor="#fff0ad" />
<titlestyle Font-Names="TimesRoman" ForeColor="#680000" font-size="20px" font-bold="true" borderwidth="2px" />
<dayheaderstyle Font-Names="TimesRoman" font-size="12px" font-bold="true" />
<todaydaystyle Font-Names="TimesRoman" backcolor="#fff282" forecolor="#680000" />
<WeekendDayStyle Font-Names="TimesRoman" BackColor="#fafad2" ForeColor="#ff0000" />

<othermonthdaystyle Font-Names="TimesRoman" forecolor="#cccccc" />
</asp:calendar>


ASP.Net Paths

Here's a list of the Path related properties on the Request object (and the Page object):

Request Property

Function and Example

ApplicationPath

Returns the a Web server relative path to your application root

/WestwindWebStore/

PhysicalApplicationPath

Returns a local file system path to your application root

D:\inetpub\wwwroot\WestWindWebStore\

PhysicalPath

Returns the full file system path to the currently executing script

D:\inetpub\wwwroot\WestWindWebStore\Item.aspx

CurrentExecutionFilePath

FilePath

Path

In most situations all of these return the virtual path to the currently executing script relative to the Web Server root.

/WestwindWebStore/item.aspx

PathInfo

Returns any extra path following the script name. Rarely used – this value is usually blank.

/WestwindWebStore/item.aspx/ExtraPathInfo

RawUrl

Returns the application relative URL including querystring or pathinfo

/WestwindWebStore/item.aspx?sku=WWHELP30

Url

Returns the fully qualified URL including domain and protocol

http://www.west-wind.com/Webstore/item.aspx?sku=WWHELP30

Page.TemplateSourceDirectory

Control.TemplateSourceDirectory

Returns the virtual path of the currently executing control (or page). Very useful if you need to know the location of your ASCX control instead of the location of the page.

/WestwindWebStore/admin


for more info. http://www.west-wind.com/weblog/posts/269.aspx

ASP.NET, C# UrlRewriting - PathInfo

ASP.NET, C# UrlRewriting - PathInfo

Change your URLs from
http://mysite.com/items.aspx?id=20&pname=TV
http://mysite.com/items.aspx?id=21&pname=DVD
http://mysite.com/items.aspx?id=22&pname=LCD ...
to
http://mysite.com/items.aspx/20/TV
http://mysite.com/items.aspx/21/DVD
http://mysite.com/items.aspx/22/LCD ...

How?

its simple

in Page1.aspx
<ul>
<li><a href="http://mysite.com/items.aspx/20/TV">TV</a></li>
<li><a href="http://mysite.com/items.aspx/21/DVD">DVD</a><
<li><a href="http://mysite.com/items.aspx/22/LCD">LCD</a></li>
</ul>

in items.aspx page
place this code

if (Request.PathInfo.Length == 0)
{ b1 = ""; b2 = ""; }
else
{
string pathinfo;
pathinfo = Request.PathInfo.Substring(1);

b1 = pathinfo.TrimEnd('/').Split('/')[0].ToString();
b2 = pathinfo.TrimEnd('/').Split('/')[1].ToString();
}

Use this kind of urls for beater search engine ranking. hope it helps ................. ;)

more info...
http://sharpertutorials.com/clean-url-structure-in-aspnet/