Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Archive for December, 2011

Ways to check whether a trigger exists in SQL Server

Posted by Viral Sarvaiya on December 13, 2011


How to find there are trigger is exists in database or not?

there are 2 ways to find the list of the trigger in database

select * from dbo.sysobjects
where OBJECTPROPERTY(id, 'IsTrigger') = 1


select * from sys.triggers

and if you want to find trigger from particular table,

exec sp_helptrigger 'TableName'


select * from sys.triggers where name = 'TableName'




Posted in Sql Server | Tagged: , , , , | Leave a Comment »

Convert Text in to Image using C#

Posted by Viral Sarvaiya on December 13, 2011

.net provide us very good functionality to Create image from text, here is function that return Bitmap and take string as a parameter.

private Bitmap CreateBitmapImage(string TextImage)
Bitmap objBmp = new Bitmap(1, 1);

int Width = 0;

int Height = 0;

// Create the Font object for the image text drawing.

Font objFont = new Font("Arial", 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);

// Create a graphics object to measure the text's width and height.

Graphics objGraphics = Graphics.FromImage(objBmp);

// This is where the bitmap size is determined.

Width = (int)objGraphics.MeasureString(TextImage, objFont).Width;

Height = (int)objGraphics.MeasureString(TextImage, objFont).Height;

// Create the bmpImage again with the correct size for the text and font.

objBmp = new Bitmap(objBmp, new Size(Width, Height));

// Add the colors to the new bitmap.

objGraphics = Graphics.FromImage(objBmp);

// Set Background color


objGraphics.SmoothingMode = SmoothingMode.AntiAlias;

objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

objGraphics.DrawString(TextImage, objFont, new SolidBrush(Color.FromArgb(102, 102, 102)), 0, 0);


return (objBmp);


Posted in .Net, ASP.NET | Tagged: , , , , , , , , | Leave a Comment »

Send Email Attachment Using A Memory Stream

Posted by Viral Sarvaiya on December 12, 2011

mainly we send attachment as a file which is already in the server, but from memory stream we can also send as a attachment in email, below is code for that,

Dim strMailServer As String = "SMTPServerName"

Dim fs As New FileStream("FilePath\FileName.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)

Dim sReader As New StreamReader(fs)

Dim objMemoryStream As New MemoryStream()

Dim sb As New System.Text.StringBuilder("")
Dim str As String

'--read through template form, replace variables and add lines to string builder

Do While sReader.Peek() >= 0

str = sReader.ReadLine()

'--replace [Date_Time]
'Replace string here



Dim Encoding As New UTF8Encoding

Dim arrByt() As Byte = Encoding.GetBytes(sb.ToString())

objMemoryStream.Write(arrByt, 0, arrByt.Length)

objMemoryStream.Position = 0

'--release file system resources





Dim objMailMessage As New MailMessage

Dim objSMTP As New SmtpClient

Dim toAddress As New MailAddress("ToEmailAddress", "ToEmailName")


Dim fromAddress As New MailAddress("FromEmailAddress", "FromEmailName")

objMailMessage.From = fromAddress

objMailMessage.IsBodyHtml = False
objMailMessage.Priority = MailPriority.Normal

objMailMessage.Subject = "EmailSubject"

objMailMessage.Body = "Email Body"

' add fax cover page as first file attachment

objMailMessage.Attachments.Add(New Attachment(objMemoryStream, "FileName.txt"))


objSMTP.Host = strMailServer


Catch ex As Exception

Throw ex

End Try


Posted in ASP.NET, feature | Tagged: , , , , , | Leave a Comment »

Get Silverlight XAP and Hosting Page URL

Posted by Viral Sarvaiya on December 5, 2011

Get the URL to the current xap file:


Get the full URL of the page hosting the xap (with QueryStrings):


Posted in .Net, ASP.NET, Silverlight, Visual Studio | Tagged: , , , , , | Leave a Comment »

%d bloggers like this: