Web Developer Friend – Viral Sarvaiya

Web Developer Friends, dot net Developer, Sql Server Developer

Prevent Silverlight XAP file from caching in your browser.

Posted by Viral Sarvaiya on January 19, 2012

Sometime when we deploy silverlight project, that happen often that when you run website it run older deploy project. because that comes from the cache,

so clear the cache of the Browser and some time that problem occur also after clearing cache.

so for that we have to force website to download new version of xap file every time when it run.

normally we have tag for XAP file, as like below

<param name="source" value="/ClientBin/SilverApp.xap" />

but we have to download our XAP file new at every run of site.

so there so many option for that.

1) changing the Assembly and File version numbers

2) GUID value for the project

but, here is the simple and best solution for that and then it worked like a charm everytime.

<param name="source" value="/ClientBin/SilverApp.xap?ignoreme=<%=System.DateTime.Now.ToUniversalTime()%>" />

Enjoy,

Posted in .Net, ASP.NET, Silverlight | Tagged: , , , , , , , , , | 1 Comment »

SQL Reporting Services Error- Maximum request length exceeded

Posted by Viral Sarvaiya on January 16, 2012

Today i upload all report of my project and get error

Error : There was an Exception running the extension specified in the config file –> maximum request length exceeded.

The basic problem here, is that your posting an amount of data to a web app larger than it is configured to accept.  Hence, it is throwing an error, and simply saying “no!”

It’s an easy fix though! You’ve got to tweak the web.config for the web app, which in the case of reporting server, is usually somewhere like this:

C:\Program Files\Microsoft SQL Server\MSRS10_50.SQLEXPRESS\Reporting Services\ReportServer

Find the web.config file for your reporting services instance, open it up, and track down the line that looks something like this

<httpRuntime executionTimeout = "9000" />

Now just add a max request length attribute in there to fix the problem, adjust your size as needed.  This is 5meg.

<httpRuntime executionTimeout = "9000" maxRequestLength="500000" />

And now you’ll need to restart IIS.  start->run->”iisreset”

Enjoy….

Posted in Report | Tagged: , , , , , , , , | 1 Comment »

RESEED/Reset Table Identity Value in sql server

Posted by Viral Sarvaiya on January 6, 2012

DBCC CHECKIDENT can reset the identity value of the table,

For example if table has 500 reords and not we want to delete all records or want to start data from 600 then this command will help us.

DBCC CHECKIDENT (Table_name, reseed, 0)

OR

DBCC CHECKIDENT (Table_name, reseed, 600)

Most of our identity we start with 1 so must have to take care that identity set to 0.

If identity is set below values that currently are in table, it will violate the uniqueness constraint as soon as the values start to duplicate and will generate error.

Enjoy…

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

Ways to check whether a trigger exists in SQL Server

Posted by Viral Sarvaiya on December 13, 2011

Hi,

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

or


select * from sys.triggers

and if you want to find trigger from particular table,


exec sp_helptrigger 'TableName'

or


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

 

Enjoy…

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.Clear(Color.White);

objGraphics.SmoothingMode = SmoothingMode.AntiAlias;

objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

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

objGraphics.Flush();

return (objBmp);
}

Enjoy….

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

sb.Append(str)

Loop

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

sReader.Close()

sReader.Dispose()

fs.Close()

fs.Dispose()

Dim objMailMessage As New MailMessage

Dim objSMTP As New SmtpClient

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

objMailMessage.To.Add(toAddress)

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"))

Try

objSMTP.Host = strMailServer

objSMTP.Send(objMailMessage)

Catch ex As Exception

Throw ex

End Try
<pre>

Enjoy…

Posted in ASP.NET, 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:
App.Current.Host.Source.AbsoluteUri

Sample:

http://www.WebsiteName.com/ClientBin/SilverlightApplicationName.xap

Get the full URL of the page hosting the xap (with QueryStrings):
HtmlPage.Document.DocumentUri.ToString()

Sample:

http://www.WebsiteName.com/SilverlightApplicationName.aspx?param=1

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

Bind Multiple Columns in Combobox in Silverlight

Posted by Viral Sarvaiya on October 15, 2011

Silverlight has simple combobox like below.

<Combobox x:Name="combo1"  Width="100" Height="30" />

we use ItemSource property for binding data to combobox.
we can set DisplayMemberPath property as like

<Combobox x:Name="combo1"  Width="100" Height="30"  DisplayMemberPath ="Name"  />

for the multiple property we can edit compbobox itemTemplate.
for that you have to remove DisplayMemberPath property from Combobox tag and use the below tag for binding multiple properties to Combobox.

<ComboBox x:Name="cboTest">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name, Mode=OneWay}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding Surname, Mode=OneWay}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

if you want to select an item and want Id of selected item then you can use SelectedValue or Selecteditem Property as like below

<ComboBox x:Name="cboTest" ItemSource="{Binding MyList, Mode=TwoWay}" SelectedValue={Binding Path=Name, Mode="TwoWay"}>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name, Mode=OneWay}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding Surname, Mode=OneWay}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

hope this will help you.

Posted in .Net, ASP.NET, Silverlight | Tagged: , , , , , | 2 Comments »

Monitoring the File System

Posted by Viral Sarvaiya on September 20, 2011

Today i get new thing in my project that use FileSystemWatcher Class, so here i explain how to monitoring the file system,

You can use the FileSystemWatcher class (part of the System.IO namespace) to respond to updated files, new files, renamed files, and other updates to the file system. First, create an instance of FileSystemWatcher by providing the path to be monitored. Then, configure roperties of the FileSystemWatcher instance to control whether to monitor subdirectories and which types of changes to monitor. Next, add a method as an event handler. Finally, set the FileSystemWatcher.EnableRaisingEvent property to true. The following code sample demonstrates a basic usage.

// Create an instance of FileSystemWatcher
FileSystemWatcher fsw = new FileSystemWatcher(Environment.GetEnvironmentVariable("USERPROFILE"));
// Set the FileSystemWatcher properties
fsw.IncludeSubdirectories = true;
fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
// Add the Changed event handler
fsw.Changed += new FileSystemEventHandler(fsw_Changed);
// Start monitoring events
fsw.EnableRaisingEvents = true;

Handling FileSystemWatcher Events When a file is changed that meets the criteria you specify, the CLR calls the FileSystemWatcher.Changed event handler for all changes, creations, and deletions. For files and folders that are renamed, the CLR calls the FileSystemWatcher.Renamed event handler. The previous code sample added the fsw_Changed method to handle the Changed event. The following code sample shows a simple way to handle the event:


static void fsw_Changed(object sender, FileSystemEventArgs e)
{
// Write the path of a changed file to the console
Console.WriteLine(e.ChangeType + ": " + e.FullPath);
}

You can use a single event handler for the Changed, Created, and Deleted events. The FileSystemEventArgs parameter provides the path to the updated file and the type of change that occurred. If you need to respond to files that are renamed, you need to create an event handler that accepts a RenamedEventArgs parameter instead of a FileSystemEventArgs parameter, as the following code sample demonstrates:


static void fsw_Renamed(object sender, RenamedEventArgs e)
{
// Write the path of a changed file to the console
Console.WriteLine(e.ChangeType + " from " + e.OldFullPath + " to " + e.Name);
}

Configuring : FileSystemWatcher Properties You can configure the following properties of the FileSystemWatcher class to control which types of updates cause the CLR to throw the Changed event:

Filter : Used to configure the filenames that trigger events. To watch for changes in all files, set the Filter property to an empty string (“”) or use wildcards (“*.*”). To watch a specific file, set the Filter property to the filename. For example, to watch for changes in the file MyDoc.txt, set the Filter property to “MyDoc.txt”. You can also watch for changes in a certain type of file. For example, to watch for changes in text files, set the Filter property to “*.txt”.

NotifyFilter Configure the types of changes for which to throw events by setting NotifyFilter to one or more of these values:

  • FileName
  • DirectoryName
  • Attributes
  • Size
  • LastWrite
  • LastAccess
  • CreationTime
  • Security

Path : Used to define the folder to be monitored. You can define the path using the FileSystemWatcher constructor. You can watch for the renaming, deletion, or creation of files or directories. For example, to watch for the renaming of text files, set the Filter property to “*.txt” and call the WaitForChanged method with a Renamed value specified for its parameter.

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

 
Follow

Get every new post delivered to your Inbox.