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
  1. create procedure dropallsp as  
  2. declare @procName varchar(500)  
  3. declare cur cursor  
  4. for Select [name] from sys.procedures where [type] = 'P' and is_ms_shipped = 0 and [name] not like 'sp[_]%diagram%'  
  5. open cur  
  6. fetch next from cur into @procName  
  7. while @@fetch_status = 0  
  8. begin  
  9. exec('drop procedure ' + @procName)  
  10. fetch next from cur into @procName  
  11. end  
  12. close cur  
  13. 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.
  1. 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:
  1. < language="javascript">  
  2.         window.location = "YourURL.aspx";  
  3.  < /script >  

Plain HTML(you can add following code between your <head> and </head> tags):
  1. < equivequiv="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:
  1. <form action="https://www.paypal.com/cgi-bin/webscr" method="post">  
  2. <input type="hidden" name="cmd" value="_s-xclick">  
  3. <input type="hidden" name="hosted_button_id" value="xxxxxx">  
  4. <input type="image" src="http://www.Mywebsiteurl.com/images/pay.jpg" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">  
  5. <img alt="" border="0" height="1" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1">  
  6. </form>  

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:
  1. <input type="hidden" name="cmd" value="_s-xclick">  
  2. <input type="hidden" name="hosted_button_id" value="xxxxxx">  
  3. <asp:imagebutton id="ImageButton1" imageurl="https://www.paypal.com/en_AU/i/scr/pixel.gif" runat="server" onclientclick="document.getElementById('aspnetForm').action='https://www.paypal.com/cgi-bin/webscr';">  
  4. </asp:imagebutton>  

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:
  1. using System;  
  2. using System.Data;  
  3. using System.Configuration;  
  4. using System.Web;  
  5. using System.Web.Security;  
  6. using System.Web.UI;  
  7. using System.Web.UI.HtmlControls;  
  8. using System.Web.UI.WebControls;  
  9. using System.Drawing;  
  10. using System.Drawing.Drawing2D;  
  11. using System.Drawing.Imaging;  
  12. using System.IO;  
  13. /// <summary>  
  14. /// Summary description for clsImageUpload : Credits : http://prajeeshkk.blogspot.com  
  15. /// </summary>  
  16. public class clsImageUpload  
  17. {  
  18. string fileName;  
  19. public clsImageUpload()  
  20. {  
  21. //  
  22. // TODO: Add constructor logic here  
  23. //  
  24. }  
  25. //This function is called from aspnet page, it takes directory name as parameter  
  26. public string HandleUploadedFile(string directory)  
  27. {  
  28. // To get the root of the web site  
  29. string root = HttpContext.Current.Server.MapPath("~/");  
  30. // clean up the path  
  31. if (!root.EndsWith(@"\"))  
  32. root += @"\";  
  33. // make a folder to store the images in  
  34. string fileDirectory = root + @"\" + directory + "\\";  
  35. // create the folder if it does not exist  
  36. // make a link to the new file  
  37.   
  38. // loop through the file in the request  
  39. for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)  
  40. {  
  41. // get the file instance  
  42. HttpPostedFile fi = HttpContext.Current.Request.Files.Get(i);  
  43. // create a byte array to store the file bytes  
  44. byte[] fileBytes = new byte[fi.ContentLength];  
  45. // fill the byte array  
  46. using (System.IO.Stream stream = fi.InputStream)  
  47. {  
  48. stream.Read(fileBytes, 0, fi.ContentLength);  
  49. }  
  50. // create a random file name  
  51. fileName = Guid.NewGuid().ToString();  
  52.   
  53. // write the resized file to the file system  
  54. File.WriteAllBytes(fileDirectory + fileName + "_thumb.jpg", ResizeImageFile(fileBytes, 75));  
  55. fileBytes = null;  
  56. }  
  57. return (fileName + "_thumb.jpg");  
  58. }  
  59. public void HandleUploadedFileUseExistingName(string directory, string fname)  
  60. {  
  61. // get the root of the web site  
  62. string root = HttpContext.Current.Server.MapPath("~/");  
  63. // clean up the path  
  64. if (!root.EndsWith(@"\"))  
  65. root += @"\";  
  66. // make a folder to store the images in  
  67. string fileDirectory = root + @"\" + directory + "\\";  
  68. // loop through the file in the request  
  69. for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)  
  70. {  
  71. // get the file instance  
  72. HttpPostedFile fi = HttpContext.Current.Request.Files.Get(i);  
  73. // create a byte array to store the file bytes  
  74. byte[] fileBytes = new byte[fi.ContentLength];  
  75. // fill the byte array  
  76. using (System.IO.Stream stream = fi.InputStream)  
  77. {  
  78. stream.Read(fileBytes, 0, fi.ContentLength);  
  79. }  
  80. // create a random file name  
  81. fileName = fname;  
  82. // write the resized file to the file system  
  83. File.WriteAllBytes(fileDirectory + fileName, ResizeImageFile(fileBytes, 75));  
  84. fileBytes = null;  
  85. }  
  86. }  
  87. /// This fuction returns a Byte array containing the resized file  
  88. private static byte[] ResizeImageFile(byte[] imageFile, int targetSize)  
  89. {  
  90. using (System.Drawing.Image oldImage =  
  91. System.Drawing.Image.FromStream(new MemoryStream(imageFile)))  
  92. {  
  93. //If you want to maintain the propotion use following code  
  94. //Size newSize = CalculateDimensions(oldImage.Size, targetSize);  
  95. //If you want to use a fixed size use following one  
  96. Size newSize = GetDimension();  
  97. using (Bitmap newImage =  
  98. new Bitmap(newSize.Width,  
  99. newSize.Height, PixelFormat.Format24bppRgb))  
  100. {  
  101. using (Graphics canvas = Graphics.FromImage(newImage))  
  102. {  
  103. canvas.SmoothingMode = SmoothingMode.AntiAlias;  
  104. canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;  
  105. canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;  
  106. canvas.DrawImage(oldImage,  
  107. new Rectangle(new Point(0, 0), newSize));  
  108. MemoryStream m = new MemoryStream();  
  109. newImage.Save(m, ImageFormat.Jpeg);  
  110. return m.GetBuffer();  
  111. }  
  112. }  
  113. }  
  114. }  
  115. /// This function Calculates the new size of the image based on the target size  
  116. private static Size CalculateDimensions(Size oldSize, int targetSize)  
  117. {  
  118. Size newSize = new Size();  
  119. if (oldSize.Height > oldSize.Width)  
  120. {  
  121. newSize.Width =  
  122. (int)(oldSize.Width * ((float)targetSize / (float)oldSize.Height));  
  123. newSize.Height = targetSize;  
  124. }  
  125. else  
  126. {  
  127. newSize.Width = targetSize;  
  128. newSize.Height =  
  129. (int)(oldSize.Height * ((float)targetSize / (float)oldSize.Width));  
  130. }  
  131. return newSize;  
  132. }  
  133. //Dimension of the images can be set here  
  134. private static Size GetDimension()  
  135. {  
  136. Size newSize = new Size();  
  137. newSize.Width = 100;  
  138. newSize.Height = 100;  
  139. return newSize;  
  140. }  
  141. }  

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