Wednesday, September 2, 2009

code for logout in C#

Try this code may this will help. Paste this code on masterpage’s load event.
If you are not using master pages then you have to paste this code of all the pages (on load event).

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

In logout page:

Session.Clear();
Session.Abandon();
// clear all session....

run ur application.............................jsm

Wednesday, August 26, 2009

send mail to user in asp.net using web.cofig

1. using namespaces like that :

using System.Net.Mail;
using System.Net;

2. write code for sending mail and get SMTP server info from web.config:

MailMessage msgObj = new MailMessage();
MailAddress addFrom = new MailAddress(strForm);msgObj.From = addFrom;msgObj.To.Add(strTo);msgObj.Priority = MailPriority.High;
msgObj.Subject = strSubject;msgObj.Body = strBody;msgObj.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings.Get("smtpserver");
smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings.Get("port"));
string Uname = ConfigurationManager.AppSettings.Get("uname");
string password = ConfigurationManager.AppSettings.Get("pass");
//smtp.DeliveryMethod = SmtpDeliveryMethod.Network;smtp.Timeout = 120000;
smtp.EnableSsl = true; // true gor gmail, false for non-SSL
smtp.Credentials = new NetworkCredential(Uname, password);
try
{
smtp.Send(msgObj);

}
catch (Exception ex){throw ex;}


3. write code in web.config inside appsetting tag.


appsettings
add value="smtpservername" key="smtpserver"
add value="25" key="port" !-- port 25 is default, 465 0r 587 for gmail .
add value="username" key="uname">
add value="password" key="pass"
/appsettings

Monday, August 10, 2009

print documents without opening MS Word C#

print documents without opening MS Word using C#


1. using namespace in aspx page :

" using System.Diagnostics; "

2. write this on any action control like Button, chkbox etc....

C# Code.....

string filePath = "D:\\Atit\\sample.doc";
ProcessStartInfo info = new ProcessStartInfo(filePath);
info.Verb = "Print";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
Response.Write("printed !");

finally , build & run ur Apllcation......

Saturday, August 8, 2009

Configuration system failed to initialize

app.config file, tags should be like that....

// app.config start................

1. start "configuration" tag.

2. start "configsection" tag and close "configsection" tag

3. start "appsetting" and close "appsetting" tag.

4. close "configuration" tag.

// end app.config..............


build & run ur Application............

Monday, August 3, 2009

add FreeTextBox Control asp.net

By Externally :

1. Add FreeTextBox Control into ToolBox.

2. Add in web.config file this :



3. add folder on ur wesite folder or project folder , when u download a freetextbox.zip file that contain aspnet_client folder.that folder add to ur website folder.

External file : ~/aspnet_client/FreeTextBox/.

4. To add FreeTextBox to an ASP.NET page, do the following:

1. Add the following line to the top of your page:
<%@ Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>

2. Add the following code between tags:


run ur application.....

could not load file or assembly FreeTextBox or one of its dependencies the parameter is incorrect exception from hresult 0x80070057 e_invalidar

this link help u to solve your problem :

http://ranafaisal.wordpress.com/2008/03/24/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies-the-parameter-is-incorrect-exception-from-hresult-0x80070057-e_invalidarg/

Saturday, July 25, 2009

how to integrate FreeTextBox in asp.net project

// how to integrate FreeTextBox in asp.net project without "validateRequest=false"

Firstly, download from this website : http://freetextbox.com/download/

After Download :

1. add toolbox item.right click on toolbar tab, choose add item and browse your .dll file.

2. drag & drop freeTextBox control on aspx page and its ID is ftbCtrl.

3. drag & drop button control from asp toolbox and its text property is "save" and ID is
"btnSave".

4. drag & drop lable for displaying content of the FreeTextBox control and its ID is "lblPreview".

5. on top of the aspx file reset <@ page language ="C#" validateRequest="false .......>

6. write code inside the save button.


lblPreview.Text = ftbCtrl.Text;

ending............