Monday, February 1, 2010
Wednesday, May 27, 2009
Runtime genrationn of Good quality Images
With one day effort , i found how to generate quality images dynamicaly
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.SessionState;
using System.IO;
public class Handler : IHttpHandler,IReadOnlySessionState
{
public void ProcessRequest (HttpContext context) {
Image img = new Bitmap(context.Session["ImagePath"].ToString());
Size _newSize = new Size(800, 800);
img = ResizeImage(img, _newSize);
using (MemoryStream stream = new MemoryStream())
{
int quality = 150; //90 is the magic setting - really. It has excellent quality and file size.
System.Drawing.Imaging.EncoderParameters encoderParameters = new System.Drawing.Imaging.EncoderParameters(1);
encoderParameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
//img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
img.Save(stream, GetEncoderInfo("image/bmp"), encoderParameters);
stream.WriteTo(context.Response.OutputStream);
}
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
private static System.Drawing.Image ResizeImage(System.Drawing.Image original, Size newSize)
{ System.Drawing.Image result = new Bitmap(newSize.Width, newSize.Height);
using(Graphics g = Graphics.FromImage(result))
{ g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.DrawImage(original, 0, 0, newSize.Width, newSize.Height); }
return result;}
public bool IsReusable {
get {
return false;
}
}
}
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.SessionState;
using System.IO;
public class Handler : IHttpHandler,IReadOnlySessionState
{
public void ProcessRequest (HttpContext context) {
Image img = new Bitmap(context.Session["ImagePath"].ToString());
Size _newSize = new Size(800, 800);
img = ResizeImage(img, _newSize);
using (MemoryStream stream = new MemoryStream())
{
int quality = 150; //90 is the magic setting - really. It has excellent quality and file size.
System.Drawing.Imaging.EncoderParameters encoderParameters = new System.Drawing.Imaging.EncoderParameters(1);
encoderParameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
//img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
img.Save(stream, GetEncoderInfo("image/bmp"), encoderParameters);
stream.WriteTo(context.Response.OutputStream);
}
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
private static System.Drawing.Image ResizeImage(System.Drawing.Image original, Size newSize)
{ System.Drawing.Image result = new Bitmap(newSize.Width, newSize.Height);
using(Graphics g = Graphics.FromImage(result))
{ g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.DrawImage(original, 0, 0, newSize.Width, newSize.Height); }
return result;}
public bool IsReusable {
get {
return false;
}
}
}
Thursday, May 21, 2009
Thursday, March 5, 2009
Some Nice sites for code search
Code Search engineshttp://www.cavdar.net/2008/08/01/my-top-10-source-code-search-engines/
http://www.search-cube.com/
http://www.crazybrowser.com/
Runtime change in HTML
Creating the html tags at run time and save
http://rtur.net/blog/post/2007/11/21/Doing-Ajax-using-client-callbacks.aspx
http://dotnetblogengine.net/
http://www.search-cube.com/
http://www.crazybrowser.com/
Runtime change in HTML
Creating the html tags at run time and save
http://rtur.net/blog/post/2007/11/21/Doing-Ajax-using-client-callbacks.aspx
http://dotnetblogengine.net/
Saturday, September 13, 2008
Code Snippets and Samples to start with WCF
Hi
Make windows communication foundation is one of the skill of your Skills set practising Code snippets @
1)WCF.netfx
2)dotnetslackers
some more i will be adding shortly......
Make windows communication foundation is one of the skill of your Skills set practising Code snippets @
1)WCF.netfx
2)dotnetslackers
some more i will be adding shortly......
Friday, September 5, 2008
WCF Videos..Worth Watching
Hello All,
Nice videos on WCF can be found
1)@ http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2006/09/13/8875.aspx
2)And some more interesting videos at
Pluralsight
Nice videos on WCF can be found
1)@ http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2006/09/13/8875.aspx
2)And some more interesting videos at
Pluralsight
Saturday, August 9, 2008
Thursday, August 7, 2008
WCF ScreenCasts And about Creating ScreenCasts
1)Visual Studio 2008 screen cast #2 - WCF By Darryl Burling
View blog @ http://blogs.msdn.com/darrylburling/archive/2007/11/04/visual-studio-2008-screen-cast-2-wcf.aspx
2)WCF Introduction Screencast by Guy Burstein
3)More on How to create Screencasts and sharing it Anywhere
View blog @ http://blogs.msdn.com/darrylburling/archive/2007/11/04/visual-studio-2008-screen-cast-2-wcf.aspx
2)WCF Introduction Screencast by Guy Burstein
3)More on How to create Screencasts and sharing it Anywhere
Tuesday, August 5, 2008
Learn with Implementation ---The WCF Videos on Channel9
1)Web Programming with WCF
You need to Install Silverlight to view this video which is readily available on the
the site
VS2008 Training Kit: Web Programming with WCF
2)You can get the Latest Video alerts from Google in you mailbox setting your search term
at http://www.google.com/alerts?hl=en&gl=
Which is the easiest and efficient way of learning new technology
You need to Install Silverlight to view this video which is readily available on the
the site
VS2008 Training Kit: Web Programming with WCF
2)You can get the Latest Video alerts from Google in you mailbox setting your search term
at http://www.google.com/alerts?hl=en&gl=
Which is the easiest and efficient way of learning new technology
Tuesday, July 22, 2008
Some Common Obstacles While Implementing WCF
1)Error:Unknown directive ServiceHost in WCF service
Solution:
Reinstall the VS2008 for fixing the error .Confliction in version 2.0.0.0 of Windows Communication Foundation (pre-release) as well as version 3.0.0.0 (rtm)causes this error
2)Sending large amount of Data with WCF service
Solution:1)WCF Message Streaming
If InsufficientMemoryException is thrown when writing to the channel
then you need to stream both request and response data from client and server
respectively..
Some more problems and solutions yet to be added.Comments are welcome from the readers
Solution:
Reinstall the VS2008 for fixing the error .Confliction in version 2.0.0.0 of Windows Communication Foundation (pre-release) as well as version 3.0.0.0 (rtm)causes this error
2)Sending large amount of Data with WCF service
Solution:1)WCF Message Streaming
If InsufficientMemoryException is thrown when writing to the channel
then you need to stream both request and response data from client and server
respectively..
Some more problems and solutions yet to be added.Comments are welcome from the readers
Thursday, July 17, 2008
Exporting Data From Excel to SqlServer
Following are the ways to export data from excel to sql server
1)With SQLBulkCopy
create file info.xls and create table in respective database named ExcelData
Source code as follows
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.Data.SqlClient;
using System.Data.OleDb;
using System.Data.Common;
public partial class ExportFromExcelToSQL : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Connection String to Excel Workbook
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\excel\Info.xls;Extended Properties=Excel 8.0";
// Create Connection to Excel Workbook
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand("Select ID,Data FROM [Sheet1$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "Data Source=ITCUBE-4M1HVRHY; Initial Catalog=ITC;User ID=cp;Password=cp;";
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "dbo.ExcelData";
bulkCopy.WriteToServer(dr);
}
}
}
}
}
2)With DTS utility of SQL
1)With SQLBulkCopy
create file info.xls and create table in respective database named ExcelData
Source code as follows
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.Data.SqlClient;
using System.Data.OleDb;
using System.Data.Common;
public partial class ExportFromExcelToSQL : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Connection String to Excel Workbook
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\excel\Info.xls;Extended Properties=Excel 8.0";
// Create Connection to Excel Workbook
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand("Select ID,Data FROM [Sheet1$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "Data Source=ITCUBE-4M1HVRHY; Initial Catalog=ITC;User ID=cp;Password=cp;";
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "dbo.ExcelData";
bulkCopy.WriteToServer(dr);
}
}
}
}
}
2)With DTS utility of SQL
Friday, July 4, 2008
Catching Errors in Event Log in root folder
Hello All,
This function helps you write the errors to event.log
which can be called in the catch block of try and catch.
public void CatchError(Exception objErr)
{
//Exception objErr = Server.GetLastError().GetBaseException(); --This is
//to be used in application_error and Page_error events
string err = "Error Caught in try and catch block \n" +
"Error in: " + Request.Url.ToString() +
"\nError Message:" + objErr.Message.ToString() +
"\nStack Trace:" + objErr.StackTrace.ToString() ;
err = err + System.DateTime.Today.ToString() +" " + txtPhoneNumber.Text +"\n";
// EventLog.WriteEntry("SAWeb", err, EventLogEntryType.Error); This s //to be used while writing to event log
//Server.ClearError();
// additional actions...
// TextWriter tw = new StreamWriter("C:/Inetpub/wwwroot/SAWeb/logs/error.log",true);
TextWriter tw = new StreamWriter(Request.PhysicalApplicationPath.ToString() + "logs\\error.log", true);
// write a line of text to the file
tw.WriteLine(err);
// close the stream
tw.Close();
}
This function helps you write the errors to event.log
which can be called in the catch block of try and catch.
public void CatchError(Exception objErr)
{
//Exception objErr = Server.GetLastError().GetBaseException(); --This is
//to be used in application_error and Page_error events
string err = "Error Caught in try and catch block \n" +
"Error in: " + Request.Url.ToString() +
"\nError Message:" + objErr.Message.ToString() +
"\nStack Trace:" + objErr.StackTrace.ToString() ;
err = err + System.DateTime.Today.ToString() +" " + txtPhoneNumber.Text +"\n";
// EventLog.WriteEntry("SAWeb", err, EventLogEntryType.Error); This s //to be used while writing to event log
//Server.ClearError();
// additional actions...
// TextWriter tw = new StreamWriter("C:/Inetpub/wwwroot/SAWeb/logs/error.log",true);
TextWriter tw = new StreamWriter(Request.PhysicalApplicationPath.ToString() + "logs\\error.log", true);
// write a line of text to the file
tw.WriteLine(err);
// close the stream
tw.Close();
}
Friday, June 20, 2008
Helpful Tips...Online...
Folder Lock without any S/W
Here you go with an alternative way to lock folders without the use of any alternative software
Open Notepad and copy the below code and save as locker.bat. Don't forget to change your password in the code it's shown the place where to type your password.
Now double click on locker .bat
First time start it will create folder with Locker automatically for u. After creation of the Locker folder, place the contents u want to lock inside the Locker Folder and run locker.bat again. To release the lock again run locker.bat. It prompts to enter your password. On entering the correct password we can unlock the folder.
I hope this comes in handy J
**********************************************************
cls
@ECHO OFF
title Folder Locker
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Locker goto MDLOCKER
:CONFIRM
echo Are you sure u want to Lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to Unlock folder
set/p "pass=>"
if NOT %pass%==type your password here goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Locker
echo Locker created successfully
goto End
:End
2)Share Folders and Files online
1)Scribd.com
2)esnips
Here you go with an alternative way to lock folders without the use of any alternative software
Open Notepad and copy the below code and save as locker.bat. Don't forget to change your password in the code it's shown the place where to type your password.
Now double click on locker .bat
First time start it will create folder with Locker automatically for u. After creation of the Locker folder, place the contents u want to lock inside the Locker Folder and run locker.bat again. To release the lock again run locker.bat. It prompts to enter your password. On entering the correct password we can unlock the folder.
I hope this comes in handy J
**********************************************************
cls
@ECHO OFF
title Folder Locker
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Locker goto MDLOCKER
:CONFIRM
echo Are you sure u want to Lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to Unlock folder
set/p "pass=>"
if NOT %pass%==type your password here goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Locker
echo Locker created successfully
goto End
:End
2)Share Folders and Files online
1)Scribd.com
2)esnips
Saturday, June 14, 2008
All about new visual studio 2008
1)Debugging the .net framework code
2)XSD TOOL
3)Hosting Indiogo webservice
4)Visual studio 2008 blogs
ScottGu's Blog
2)XSD TOOL
3)Hosting Indiogo webservice
4)Visual studio 2008 blogs
ScottGu's Blog
Tuesday, June 10, 2008
Thursday, May 15, 2008
Frequently needed source Code for WebApplications
In this post I am going to enlist the sources for generalise asp.net web applications
1)Spellcheck for Web
Its a very easy way to integrate the spellchecker with less efforts
step I Download the required files
Extract and copy
webdir.wsf ,bin ,dic ,doc ,lib, src, web.config files and folders to root folder
step II Just include the js file spell.js
step III Call the function checkSpelling() on button click
2)Hidden control to get javascript variable value at server side
1)Spellcheck for Web
Its a very easy way to integrate the spellchecker with less efforts
step I Download the required files
Extract and copy
webdir.wsf ,bin ,dic ,doc ,lib, src, web.config files and folders to root folder
step II Just include the js file spell.js
step III Call the function checkSpelling() on button click
2)Hidden control to get javascript variable value at server side
Thursday, May 8, 2008
Hands-On articles by MVPs
1)Articles by Bilal Haider on aspalliance
2)Some Practicals using Ajax
3)Matt Bersett's excellent Articles
4)Learn In asynchronus Way
....Some more yet to be added
2)Some Practicals using Ajax
3)Matt Bersett's excellent Articles
4)Learn In asynchronus Way
....Some more yet to be added
Convering SQL resultset to XML file
Hello All,
Here's the simplest way to convert SQL result to XML output
-- declare an XML variable
DECLARE @x XML
SET @x = ' '
-- create another XML variable
DECLARE @t XML
SELECT @t = ( SELECT TOP 3 name FROM sys.tables FOR XML AUTO)
-- insert the second XML variable to the first one
SET @x.modify( '
insert sql:variable("@t")
as last into (/Root)[1] ' )
-- Let us check the results
SELECT @x
/*
*/
Here's the simplest way to convert SQL result to XML output
-- declare an XML variable
DECLARE @x XML
SET @x = '
-- create another XML variable
DECLARE @t XML
SELECT @t = ( SELECT TOP 3 name FROM sys.tables FOR XML AUTO)
-- insert the second XML variable to the first one
SET @x.modify( '
insert sql:variable("@t")
as last into (/Root)[1] ' )
-- Let us check the results
SELECT @x
/*
*/
Monday, May 5, 2008
Adding Attributes to Server Controls
Hi
If you dont find the required property of a partcular control like Linkbutton
Add the attributes to this control as follows
lnkButton.Attributes.Add("Target", "frame");
Basicaly when linkbutton is rendered at client side ,its in form of anchor control
so All server controls are have the attributes of corresponding html controls
in above case linkbutton have attributes of anchor control.
If you have additional comments on this .please post your most valuable comments
thanxs
If you dont find the required property of a partcular control like Linkbutton
Add the attributes to this control as follows
lnkButton.Attributes.Add("Target", "frame");
Basicaly when linkbutton is rendered at client side ,its in form of anchor control
so All server controls are have the attributes of corresponding html controls
in above case linkbutton have attributes of anchor control.
If you have additional comments on this .please post your most valuable comments
thanxs
Subscribe to:
Posts (Atom)
Talk to Me
Email Subscriptions
Time is Money
My Random Musings
Powered by Stuff-a-Blog
Blog Archive
About Me
- Swati Jain
- गम मनाने के लिए वक्त नहीं, ladhai के लिए bhi वक्त नही वक्त हैं तो सिर्फ इक saphal कोशिश मैं जुट जाने के लिए isme शक की गुंजाईश ही नही, पूरा ऐतबार हैं सफलता यही हैं ..यही हैं.. यही कही हैं जिसे पाने मैं सिर्फ चंद लम्हों की दुरी हें -- स्वाति जैन Software Developer MCTS Sharepoint 2010(70-573) Pune India