0
Posted on 5:20 AM by prajeesh and filed under ,
Here is the SQL query to create a stored procedure that deletes all stored procedures in a database


create procedure dropallsp as
declare @procName varchar(500)
declare cur cursor
for Select [name] from sys.procedures where [type] = 'P' and is_ms_shipped = 0 and [name] not like 'sp[_]%diagram%'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur
Shout it kick it on DotNetKicks.com
0
Posted on 5:13 AM by prajeesh and filed under ,
Here is an easy way to drop all tables in a database using a single query.

exec sp_msforeachtable 'Drop table ?'

As it is an undocumented stored procedure it may be get removed any time without any notification. Shout it kick it on DotNetKicks.com
0
Posted on 2:05 PM by prajeesh and filed under
Microsoft Launched a new community portal for developers to thrive your career, this portal helps you to find a job, training, trial software's and community support for developers.
URL is : http://www.microsoft.com/click/thrivedev/ Shout it kick it on DotNetKicks.com
0
Posted on 1:24 PM by prajeesh and filed under ,
In ASP.net we are using Response.Redirect or Server.Transfer for redirect to another page, this Redirection can also be done using Javascript or HTML
javascript:

< language="javascript">
window.location = "YourURL.aspx";
< /script >

Plain HTML(you can add following code between your <head> and </head> tags):

< equiv="REFRESH" content="0;url=yourURL.aspx">
Shout it kick it on DotNetKicks.com
1
Posted on 12:47 PM by prajeesh and filed under
In ASP.net we are redirecting to a page using Response.Redirect("PageName.aspx") ; or
using Server.Transfer("PageName.aspx"); difference between these two commands are
Response.Redirect tells browser to redirect to another page where Server.Transfer instead of telling the browser it changes the focus of the web server to another page so it reduces HTTP requests and run your application faster also browser url will be same, please note that Server.Transfer can only used for redirection between the sites running in same server.
If you set PreserveForm parameter True then existing query strings and form values are available in next page too.


Shout it kick it on DotNetKicks.com
0
Posted on 1:29 PM by prajeesh and filed under , , ,
Me and my colleague Anurag were trying to integrate a Paypal button in one of our recent project, we copied the button code available from Paypal website to our ASP.NET page and it was not worked and button click results only in a postback, at last we realized that it wont work as button code contained a form and ASP.net will not support more than one form in a page.
The button code we got from Paypal was like below:








We googled a lot to overcome this situation and finally we got a quick solution from Chyake Uchaya's blog, but the solution was not worked well in Mozilla, we done minor changes in the code and it worked perfectly finally, here is the code:





if you are not using Master pages, you can replace getElementById('aspnetForm') with getElementById('form1') or the form name you are using. Shout it kick it on DotNetKicks.com
0
Posted on 3:00 AM by prajeesh and filed under ,


Microsoft corporation announces Windows 7 pricing and upgrade option program.
So here’s the low-down on pricing for Windows 7. The estimated retail prices for upgrade packaged retail product of Windows 7 in the U.S. are:
Windows 7 Home Premium (Upgrade): $119.99
Windows 7 Professional (Upgrade): $199.99
Windows 7 Ultimate (Upgrade): $219.99
And the estimated retail prices for full packaged retail product of Windows 7 in the U.S. are:
Windows 7 Home Premium (Full): $199.99
Windows 7 Professional (Full): $299.99
Windows 7 Ultimate (Full): $319.99
This means that Windows 7 Home Premium full retail product is $40.00 less than Windows Vista Home Premium today.

Read full story here Shout it kick it on DotNetKicks.com
0
Posted on 12:52 AM by prajeesh and filed under , ,
Many asp.net communities and discussion forums are flooded with questions on how to resize images while uploading or how to generate image thumbnails while uploading an image, i have seen many posts giving the solution, here i am going to combine some solutions and created a simple solution.
Another feature of this solution is you can upload any number of images at a time.
Here is the code:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
///
/// Summary description for clsImageUpload : Credits : http://prajeeshkk.blogspot.com
///

public class clsImageUpload
{
string fileName;
public clsImageUpload()
{
//
// TODO: Add constructor logic here
//
}
//This function is called from aspnet page, it takes directory name as parameter
public string HandleUploadedFile(string directory)
{
// To get the root of the web site
string root = HttpContext.Current.Server.MapPath("~/");
// clean up the path
if (!root.EndsWith(@"\"))
root += @"\";
// make a folder to store the images in
string fileDirectory = root + @"\" + directory + "\\";
// create the folder if it does not exist
// make a link to the new file

// loop through the file in the request
for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
{
// get the file instance
HttpPostedFile fi = HttpContext.Current.Request.Files.Get(i);
// create a byte array to store the file bytes
byte[] fileBytes = new byte[fi.ContentLength];
// fill the byte array
using (System.IO.Stream stream = fi.InputStream)
{
stream.Read(fileBytes, 0, fi.ContentLength);
}
// create a random file name
fileName = Guid.NewGuid().ToString();

// write the resized file to the file system
File.WriteAllBytes(fileDirectory + fileName + "_thumb.jpg", ResizeImageFile(fileBytes, 75));
fileBytes = null;
}
return (fileName + "_thumb.jpg");
}
public void HandleUploadedFileUseExistingName(string directory, string fname)
{
// get the root of the web site
string root = HttpContext.Current.Server.MapPath("~/");
// clean up the path
if (!root.EndsWith(@"\"))
root += @"\";
// make a folder to store the images in
string fileDirectory = root + @"\" + directory + "\\";
// loop through the file in the request
for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
{
// get the file instance
HttpPostedFile fi = HttpContext.Current.Request.Files.Get(i);
// create a byte array to store the file bytes
byte[] fileBytes = new byte[fi.ContentLength];
// fill the byte array
using (System.IO.Stream stream = fi.InputStream)
{
stream.Read(fileBytes, 0, fi.ContentLength);
}
// create a random file name
fileName = fname;
// write the resized file to the file system
File.WriteAllBytes(fileDirectory + fileName, ResizeImageFile(fileBytes, 75));
fileBytes = null;
}
}
/// This fuction returns a Byte array containing the resized file
private static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
using (System.Drawing.Image oldImage =
System.Drawing.Image.FromStream(new MemoryStream(imageFile)))
{
//If you want to maintain the propotion use following code
//Size newSize = CalculateDimensions(oldImage.Size, targetSize);
//If you want to use a fixed size use following one
Size newSize = GetDimension();
using (Bitmap newImage =
new Bitmap(newSize.Width,
newSize.Height, PixelFormat.Format24bppRgb))
{
using (Graphics canvas = Graphics.FromImage(newImage))
{
canvas.SmoothingMode = SmoothingMode.AntiAlias;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
canvas.DrawImage(oldImage,
new Rectangle(new Point(0, 0), newSize));
MemoryStream m = new MemoryStream();
newImage.Save(m, ImageFormat.Jpeg);
return m.GetBuffer();
}
}
}
}
/// This function Calculates the new size of the image based on the target size
private static Size CalculateDimensions(Size oldSize, int targetSize)
{
Size newSize = new Size();
if (oldSize.Height > oldSize.Width)
{
newSize.Width =
(int)(oldSize.Width * ((float)targetSize / (float)oldSize.Height));
newSize.Height = targetSize;
}
else
{
newSize.Width = targetSize;
newSize.Height =
(int)(oldSize.Height * ((float)targetSize / (float)oldSize.Width));
}
return newSize;
}
//Dimension of the images can be set here
private static Size GetDimension()
{
Size newSize = new Size();
newSize.Width = 100;
newSize.Height = 100;
return newSize;
}
}

You can download source code from here Shout it kick it on DotNetKicks.com
0
Posted on 10:09 AM by prajeesh and filed under
In some situations you may need to convert your data table to data reader, suppose you have a Data table named dt and etDataFromDB() is a function that returns a data table, here is the steps to convert data table to data reader.
DataTable dt = new DataTable();
dt = getDataFromDB();
DataTableReader dtr;
dtr = dt.CreateDataReader();
while (dtr.Read())
{
//Do your tasks

} Shout it kick it on DotNetKicks.com