Skip to main content

Posts

Showing posts from September, 2008

Get a copy of dll in GAC (or) add Reference to a dll in GAC

Sometimes in .net application we need to have a copy of a dll which is available in GAC. But when we view the GAC through C:\Windows\assembly folder or RunĂ  assembly it will show like thisUsing this we cannot copy the dll. Only uninstall option is available.To view the available dll using the naked eye follow the stepsDot net have a dll file Shfusion.dll which is a Assembly Cache Viewer (Shfusion.dll) is a Windows shell extension that allows you to view and manipulate the contents of the global assembly cache using Windows Explorer. Shfusion.dll is located in the <Windows Folder>\Microsoft.NET\Framework\vx.x.xxxx folder, where x.x.xxxx is the version and build number of the .NET Framework you are using. uninstall the dll using the following command in the run dialog box.regsvr32 -uC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dllNow type assembly in the Run dialog box.Now you will see the folder view of the GAC. copy the dll you wantTo get back to the p…

How To Resolve The Google Chrome Error "The application failed to initialize properly (0xc0000005)"

Adding --no-sandbox at the end of the :target" link in google chrome shortcut on the desktop icon

C# The process cannot access the file because it is being used by another process

This error message is mostly comes up, when you try to access a file which is opened by another process. You may open an image file in one of your form in a picturebox with using ImageFromFile or something. I mostly use memorystream to open an image. After read it in byte[] write it into a stream and close it.You can check whether a file is being used or not with a simple function.Try to open a file with none share.publicbool IsFileUsedbyAnotherProcess(string filename) { try { File.Open(filename), FileMode.Open, FileAccess.Read, FileShare.None); } catch (System.IO.IOException exp) { returntrue; } returnfalse; }This function will return true if the file because it is being used by another process or not.

Enumeration and Iterators

An enumerator is a read-only, forward-only cursor over a sequence of values. An enumerator is an object that either:Implements IEnumerator or IEnumeratorHas a method named MoveNext for iterating the sequence, and a property called Current for getting the current element in the sequence The foreach statement iterates over an enumerable object. An enumerable object is the logical representation of a sequence, and is not itself a cursor, but an object that produces cursors over itself. An enumerable object either:Implements IEnumerable or IEnumerableHas a method named GetEnumerator that returns an enumeratorIterators An iterator is a method, property, or indexer that contains one or more yield statements. An iterator must return one of the following four interfaces (otherwise, the compiler will generate an error): // Enumerable interfaces System.Collections.IEnumerable System.Collections.Generic.IEnumerable // Enumerator interfaces System.Collections.IEnumerator Syste…

How To Avoid conflicts in C#

If you really want to use an identifier that clashes with a keyword, you can qualify it with the @ prefix. For instance: class class {...} // illegal class @class {...} // legalThe @ symbol doesn't form part of the identifier itself, so @myVariable is the same as myVariable. check out this example using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication7 { class Program { staticvoid Main(string[] args) { int @int = 10; double @double = 10.121; float @float = (float)(@int + @double); Console.WriteLine(@float.ToString()); Console.Read(); } } }

How To Pass multiple values to CommandArgument

In this post i will show you that how you can pass the multiple valuesCommandArgument... <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultipleCommandArgument.aspx.cs" Inherits="MultipleCommandArgument" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="Server"AutoGenerateColumns="False"OnRowCommand="GridView1_RowCommand"><Columns><asp:BoundFieldDataField="carid"HeaderText="Card Id"/><asp:BoundFieldDataField="Year"HeaderText="year"/><asp:TemplateField><ItemTemplate&…

How To Pass Value from database to google map( javascript function)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GoogleMap.aspx.cs" Inherits="GoogleMap" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="Server"><metahttp-equiv="content-type"content="text/html; charset=utf-8"/><title>Google Maps JavaScript API Example</title><scriptsrc="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjQ5pL86XOoQ41VopETg1BxRfqogRWDFFWKC2bFG72235ZrnYERRoUjFELdorAiLMorc8KixeuNcskQ"type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[function load() { if (GBrowserIsCompatible()) { var lat = document.getElementById("lat").value; var lon = document.getElementById("lon").value; …

How To Add Design Time Support to Custom Controls

In this post i will show how to create custom control and also how to add design time support . When inheriting from the WebControl class, you must override the Render method to provide the desired output. The following is a code sample of LogoControl that contains a property for the LogoUrl and the CompanyName: using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel.Design; using System.Drawing; using System.ComponentModel; namespace CustomControl { [Designer("CustomControl.LogoControlDesigner, CustomControl")] [ToolboxData(@"<{0}:LogoControl runat=""server"" CompanyName="" "" LogoUrl="" "" />")] publicclass LogoControl : WebControl { public LogoControl() { } publicstring LogoUrl { get { return _logoUrl; } set { _logoUrl = value; } } …

How To Add calendar control inside a GridView

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CalInsideGridView.aspx.cs" Inherits="CalInsideGridView" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="Server"AutoGenerateColumns="False"><Columns><asp:BoundFieldDataField="Title"HeaderText="Title"/><asp:TemplateFieldHeaderText="Year"><ItemTemplate><asp:TextBoxID="text1"runat="server"></asp:TextBox><asp:CalendarID="Cal1"runat="Server"OnSelectionChanged="Cal1_SelectionChanged">…

How To Encrypt Connection Strings ?

The connectionStrings element can be encrypted by running the Visual Studio 2005 Command Prompt, executing the following command, and specifying the full path to your Web site folder: aspnet_regiis -pef "connectionStrings" "C:\...\EncryptWebSite" Note that the –pef switch requires you to pass the physical Web site path, which is the last parameter. Be sure to verify the path to your Web.config file. The encrypted Web.config file will look like the following:

How To Create a schedule using asp.net Calendar Control

Many people think that the Calendar control is only used as a date picker control, but the Calendar control can also be used to display a schedule. The trick to using the Calendar control to display scheduled items and special days is to make the control large enough to display text in each day, and then add Label controls (or other controls) to the Cell object’s Controls collection in the DayRender event handler. The following example shows how a Calendar control can be used as a schedule display showing special days. In this example, a Web page was created and a Calendar control was added to the page. The following code was added to the code-behind page to show how the Calendar control’s properties can be set programmatically and the Calendar control events can be used. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Calender2.aspx.cs" Inherits="Calender2" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN&qu…

How To Export GridView to Excel

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportToExcel.aspx.cs" Inherits="ExportToExcel" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="server"BackColor="LightGoldenrodYellow"BorderColor="Tan"BorderWidth="1px"CellPadding="2"Font-Names="Tahoma"ForeColor="Black"GridLines="None"Width="300px"AutoGenerateColumns="False"><FooterStyleBackColor="Tan"/><SelectedRowStyleBackColor="DarkSlateBlue"ForeColor="GhostWhite"/><PagerS…

HowTo: Display a radiobuttonlist with images

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadioListImage.aspx.cs" Inherits="RadioListImage" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:RadioButtonListID="rdoI"runat="Server"></asp:RadioButtonList></div></form></body></html>using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; publicpartialclass RadioListImage : System.Web.UI.Page { prot…

How To Access Gridview row information inside RowCommand

In .net 1.1, the GridCommandEventArgs used to give access to the row that triggered the command. In .net 2.0, it isn't as obvious as that. Fritz posted an excellent discussion on the matter, and i'm just posting his 2-line solution here for reference. If your button is a ButtonField, then you can access the index of the item via e.CommandArgument. This may be enough information to do whatever you need. If your button is a LinkButton in a TemplateField, you have to add the CommandArgument as an attribute to the LinkButton: CommandArgument='<%# Eval("id") %>'Then in the code behind for RowCommand, you can use the following syntax:string id = (string)e.CommandArgument;

Compiling Asp.Net 2.0 to a single assembly

I wanted to install my web application assembly into the GAC, but this is made more complicated by the multitude of assemblies produced by VS when i publish the web site. On the newsgroups, i found some talk of a tool called Merge_Aspnet.exe but i couldn't find it anywhere. Eventually i found it as a download on MSDN, it is bundled as part of the Web Deployment Projects. You install it, and then right-click your project in VS and you should see a new menu item "Add Web Deployment Project". I am baffled as to why they didn't just add a new project type in the list of projects under "Deployment". There is a link to "Search online templates" so i think it should really be available there. but it looks like MS did a hack just to add in a new item to the project context menu. but it works... so i'll stop complaining.

GridView Javascript Click Row and Webservice

This postshows 2 common tasks with the ASP.NET GridView: Binding a List (generic) of objects as DataSource and on clicking a row, getting the values of the selected row by a javascript function. In the example a List with User-objects is displayed. On clicking a row containing the data of a User-object, the Id of the object is used to get the address of the user by an Ajax-call and display it in a details-field.Binding objects to a GridView in ASP.NET is a well supported feature. You need to add the objects you like to bind to a Collection like an IList<> and assign the list as datasource to the GridView. The mechanism of binding works by reading out the properties of the bound objects. Each property of your object maps to a column in the GridView. So binding and displaying your data isn't very hard. A little more tricky is the procedure to refer to your data in a client-script. There are some use-cases where you need this, for example when you want to get some detail-info…

Using Event Delegates in the controls nested within a GridView

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewCustomEvent.aspx.cs" Inherits="GridViewCustomEvent" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><table><tr><tdstyle="height: 194px"><h3> Using Event Delegates in the controls nested within a GridView</h3><p> In this sample I use event delegates to process an event triggered by a child control within a gridview</p><table><tr><tdrunat="server"id="tdDG3"></td><tdrunat="serve…