Monday, February 15, 2010

HOw to see HIDDEN files and folders from windows which cant see due to virusss

(Go to Start --> Run, then type Regedit
2. Navigate to the registry folder HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\
CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOW ALL
3. Find a key called CheckedValue.
4. Double Click CheckedValue key and modify it to 1. This is to show all the hidden files.)

Saturday, February 13, 2010

HOw to delete all the files and folders from the directory

public object delDirectory(string dirPath)
{

if (!(Directory.Exists(dirPath)))
{
return false;
}
string[] fileEntries = Directory.GetFiles(dirPath);
foreach (string fileName in fileEntries)
{
File.Delete(fileName);
}
string[] subdirectoryEntries = Directory.GetDirectories(dirPath);
foreach (string subdirectory in subdirectoryEntries)
{
delDirectory(subdirectory);
}
Directory.Delete(dirPath);
return true;
}

How to change gridview header on row created.

protected void grvUserThread_RowCreated(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow headerRow = e.Row;
Label lb = new Label();
lb = (Label)e.Row.FindControl("lblabc");
lb.Text = "Thread: " + Thread;
}
}

HOw to use CURSOR in PROCEDURE

set ANSI_NULLS OFF
set QUOTED_IDENTIFIER OFF
GO

CREATE PROCEDURE [dbo].[PROCNAME]
(
@FeedbackIDStr varchar(5000)/*Selected FeedbackID like 2,4,5,6,7 */
)
AS
Declare @TFid int
Declare @tempTblFid TABLE (idx smallint Primary Key, FeedbackID int)

INSERT INTO @tempTblFid SELECT * from fn_Split(@FeedbackIDStr,',')

/*Declare Cursor for getting FeedbackID and update into tblName*/
Declare curTempFeedback Cursor Fast_Forward for
select FeedbackID from @tempTblFid
Open curTempFeedback
fetch next from curTempFeedback into @TFid
While @@Fetch_Status = 0
BEGIN
UPDATE [tblName]
SET IsAddedToFAQ ='True' where FeedbackID=@TFid

INSERT INTO [tblName]
SELECT Subject,Comment,getdate(),'False',FeedbackID from [tblName] where FeedbackID=@TFid;

fetch next from curTempFeedback into @TFid
END
CLOSE curTempFeedback
DEALLOCATE curTempFeedback

HOW TO KILL PROCESS IN FINALLY BLOCK

catch (Exception ex)
{

}
finally
{
System.Diagnostics.Process[] prs = System.Diagnostics.Process.GetProcesses();

foreach (System.Diagnostics.Process proces in prs)
{

if (proces.ProcessName.ToUpper() == "EXCEL")
{
proces.Refresh();
if (!proces.HasExited)
proces.Kill();
}
}
}
}

HOW TO USE SIGNOUT FUNCTION

protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] != null)
{
BLL_Users objUser = new BLL_Users();
objUser.LogOutUser(Convert.ToInt16(Session["UserID"]));
}
FormsAuthentication.SignOut();
Session.Abandon();
Response.Redirect("Login.aspx", false);
}


}

HOW TO PASS/USE MULTIPLE Parameters in BLL and DAL

public void AddUserLogs(int uid, string ip, string UserSessionID, string browser, string os)
{
try
{
DAL_Users.AddUserLogs(uid, ip, UserSessionID, browser, os);
}
catch (Exception ex)
{
ex = ex;
}
}

public static void AddUserLogs(int uid, string ip, string UserSessionID, string browser, string os)
{
try
{
string strCon = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection con = new SqlConnection();
con.ConnectionString = strCon;
SqlHelper.ExecuteNonQuery(con, CommandType.StoredProcedure, "360LMS_AddUserLoginLogs", new SqlParameter("@UserID", uid), new SqlParameter("@IP", ip), new SqlParameter("@Browser", browser), new SqlParameter("@OS", os), new SqlParameter("@SessionID", UserSessionID));
}
catch (Exception ex)
{
ex = ex;
}

}