Sunday, October 4, 2009

how to clear cookies/cache for browser using C# .NET

using System.IO;
void clearIECache()
{
ClearFolder (new DirectoryInfo (Environment.GetFolderPath
(Environment.SpecialFolder.InternetCache)));
}

void ClearFolder (DirectoryInfo folder)
{
foreach (FileInfo file in folder.GetFiles())
{ file.Delete(); }
foreach (DirectoryInfo subfolder in folder.GetDirectories())
{ ClearFolder(subfolder); }
}

public static void Main( )
{
new Test().clearIECache ();
}

Saturday, August 22, 2009

this.controller is null or not an object reportviewer / Report Viewer Control missing Header Icons

In IIS 7, we need to make sure we configurate the ReportViewer handler.

You can follow these steps:

o Open Internet Information Services (IIS) Manager and select your Web application.

o Under IIS area, double-click on Handler Mappings icon.

o At the Action pane on your right, click on Add Managed Handler.

o At the Add Managed Handler dialog, enter the following:
Request path: Reserved.ReportViewerWebControl.axd
Type: Microsoft.Reporting.WebForms.HttpHandler
Name: Reserved-ReportViewerWebControl-axd

o Click OK.

http://forums.asp.net/t/1361939.aspx

For more information, see http://otkfounder.blogspot.com/2007/11/solving-reportviewer-rendering-issue-on.html

Friday, July 31, 2009

Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dep

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Source Error:

Line 41:
Line 42:
Line 43:
Line 44:
Line 45:



Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


Solution

This error means you're using the SQL Server Reporting Services ReportViewer control in your web application
, and the server can't find the proper DLL. All you have to do is deploy them to your server. With Visual Studio
2008, the location of the ReportViewer DLLs has changed. You now find them at C:\Program Files\Microsoft Visual Studio 9.0\ReportViewer.
The first way to get these on your server, and this only works if you run your own server, is to directly copy them into the C:\Windows\assembly folder, and reboot the server (this reloads the GAC). If a reboot is out of the question, you can use GACUTIL.EXE to copy and register the DLLs.
If you're in a shared hosting environment, reference the DLLs from the VS 9 path listed above, and set the Copy Local=True (select the DLL and open the Properties tab). This will copy the DLLs into your applications BIN folder, and look for them there first. You can then deploy to a shared host, making sure to copy all the contents of BIN.

Dll name

paste following dll in bin folder or windows folder

1> Microsoft.ReportViewer.Common.dll
2> Microsoft.ReportViewer.ProcessingObjectModel.DLL
3> Microsoft.ReportViewer.WebForms.dll
4> Microsoft.ReportViewer.WinForms.dll

Wednesday, July 29, 2009

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005.

Best Solution :
1>http://blog.crowe.co.nz/archive/2006/03/02/589.aspx
2>http://forums.asp.net/t/1309171.aspx

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.

Best Solution :
1>http://blog.crowe.co.nz/archive/2006/03/02/589.aspx
2>http://forums.asp.net/t/1309171.aspx

Password Encryption in C# + SHA1

public static string EncryptPassword(string Password)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "SHA1");
}

How to fill year in dropdown list

public static void FillYear(DropDownList cmb)
{
ListItem li;
for (int i = 1990; i <= DateTime.Now.Year; i++)
{
li = new ListItem(i.ToString(), i.ToString());
cmb.Items.Add(li);
}
}

How to change gridview row color on mouse over ?

write this code on row command event



foreach (GridViewRow gvr in gv.Rows)
{
//gvr.Attributes.Add("onMouseover", "MouseOnGridViewRow(this)");
//gvr.Attributes.Add("onMouseout", "MouseOffGridViewRow(this)");


if (gvr.RowState == DataControlRowState.Alternate)
{
gvr.Attributes.Add("onmouseover", "this.style.backgroundColor='#f1eee9';");
gvr.Attributes.Add("onmouseout", "this.style.backgroundColor='#F6F5F1';");
}
else
{
gvr.Attributes.Add("onmouseover", "this.style.backgroundColor='#f1eee9';");
gvr.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';");
}
}

how to delete file from folder in C#,asp.net ?

string FileName =test.doc";
string FilePath = "c:\\" + FileName;
FileInfo TheFile = new FileInfo(FilePath);
if (TheFile.Exists)
{
TheFile.Delete();
//File.Delete(FilePath);
}
else
{
throw new FileNotFoundException();
}

how to create word document in C#,asp.net ?

First add refrence Microsoft.word 11 from com

or in asp.net

using Microsoft.Office.Interop.Word;



object fileName = "c://MyFile.doc";
object novalue = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.ApplicationClass objWord = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document objWordDoc = objWord.Documents.Add(ref novalue, ref novalue, ref novalue, ref novalue);
objWord.Selection.TypeText("Test Dcument");
objWord.Selection.TypeParagraph();
objWordDoc.SaveAs(ref fileName, ref novalue, ref novalue, ref novalue,
ref novalue, ref novalue, ref novalue, ref novalue, ref novalue,
ref novalue, ref novalue, ref novalue, ref novalue, ref novalue, ref novalue, ref novalue);
objWord.Quit(ref novalue, ref novalue, ref novalue);