Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Tuesday, May 18, 2010

check folder / directory is exist or not...


check folder / directory is exist or not...


bool exists = System.IO.Directory.Exists(@"c:\myPath");

Monday, May 3, 2010

Split a path into a string[] in C# .net




using System.Text.RegularExpressions;

string inputString = @"C:\somedir\somefile.txt";
string[] parts = Regex.Split(inputString,@"\\");
foreach (string s in parts)
{
// process the strings
}

Answer

s[0]=C:
s[1]= somedir;
s[2]=somefile.txt

Saturday, May 1, 2010

Add/Change Page Meta tags dynamically in asp.net using C#.

Meta tags are very much important for you web page, search engine use Meta tags to index you site. So some time we need to change meta tags dynamically in case of dynamic pages in asp.net.

Create a web application in c#

Drag a button and one textbox on the form

Then write code on form load event

C#

protected void Page_Load(object sender, EventArgs e)

{

HtmlHead headTag = (HtmlHead)this.Header;

// Set the page title

headTag.Title = "Title of Page";

// Add a Description meta tag

HtmlMeta PagemetaTag = new HtmlMeta();

PagemetaTag.Name = "Description";

PagemetaTag.Content = "Customized Description tag of the page";

headTag.Controls.Add(PagemetaTag);

// Add a Keywords meta tag

PagemetaTag = new HtmlMeta();

PagemetaTag.Name = "Keywords";

PagemetaTag.Content = "Customized Keyword tag of the page";

headTag.Controls.Add(PagemetaTag);

}

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim headTag As HtmlHead = CType(Me.Header, HtmlHead)

' Set the page title

headTag.Title = "Title of Page"

' Add a Description meta tag

Dim PagemetaTag As HtmlMeta = New HtmlMeta()

PagemetaTag.Name = "Description"

PagemetaTag.Content = "Customized Description tag of the page"

headTag.Controls.Add(PagemetaTag)

' Add a Keywords meta tag

PagemetaTag = New HtmlMeta()

PagemetaTag.Name = "Keywords"

PagemetaTag.Content = "Customized Keyword tag of the page"

headTag.Controls.Add(PagemetaTag)

End Sub

This is the simple code to change meta tags of your page dynamically.

Tuesday, February 9, 2010

Get current page name in ASP.Net

public string GetCurrentPageName() 
{
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
return sRet;
}

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

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