Skip to main content

Posts

Showing posts from July, 2011

How to delete and create windows service using SC

This post is going to be a really small and simple. In this I will just write down the use of SC utility to delete and create windows services. There are lot of resources on web but I am just posting it to have it for my reference :) as I perform these actions quiet often. How to create .NET windows service :- On local computer Go to Run -> Cmd use SC -  sc create <service name>  binpath= "<exe folder>\<exe name>" e.g. sc create MySampleService binpath= "D:\MySampleServiceProject\MySampleService.exe" point to note: There should not be a space between binPath and '='. Service name should be in double quotes ("). There must be a space between '=' and the services exe path. On Remote Computer Go to Run -> Cmd  use SC -  sc <remoteservername> create <service name>  binpath= "<exe folder>\<exe name>" How to delete.NET windows service :- sc delete <servicename>

Detect ASP.NET session timeout

HTTPContext object - Provides access to the entire current context (including the request object). You can use this class to share information between pages. It is created early in the asp.net pipeline. It is also used to map the request to a session. Thus, we can use this object to find out whether the session has expired or not. In my application I am using a master page for the login page and I hope that is what you all will be doing. This is the code which I have used to find redirect the user to another URL if the session has expired. protected override void OnInit(EventArgs e)     {         base.OnInit(e);         if (Context.Session != null)         {             //check whether a new session was generated             if (Session.IsNewSession)             {                 //check whether a cookies had already been associated with this request                 HttpCookie sessionCookie = Request.Cookies["ASP.NET_SessionId"];            

Partial Search in sql server

Here I am not going to talk about fulltext search as generally in small applications which not that expensive servers we do not really go for full text indexes. Thus we are going to talk about wild card search. Now a days providing search facility to end user has become quite normal. Users generally will have 'n' fields to search. They can search by providing values for all fields or they may provide values for only one field. There are two solutions to this:- The one i like - I have not put any validation in place which we should as if there is no parameter specified the procedure will fail because of bad syntax as there will be a bad where clause. Thus check if no parameter is spec CREATE PROCEDURE SearchProcedureName         -- Add the parameters for the stored procedure here         @Name VARCHAR(100),         @Id VARCHAR(10),         @error int output AS BEGIN set @error = -1 if((ISNULL(@Name, '') ='') and (ISNULL(@Id, '') ='

Displaying image is a gridview - ImageField

Can not display images in gridview. Images are not getting displayed in gridview. Quite often I have seen people getting bugged by this problem. This problem arises normally due to wrong image URL. This is because web server was not able to find the image and thus did not return a valid URL. Consider a scenario where in my D: drive I have a folder name Images now if there are few images in it and I just wrote a small program to read the file name and display image using a gridview like this:- Default.aspx - <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"     CodeBehind="Default.aspx.cs" Inherits="GridView_Image._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderI