Friday, September 24, 2010

GridView must be placed inside a form tag with runat=server

I was creating an online test and I wanted to email the test results by topic to an email distribution list. I have a panel which has two child controls, a label with an overall % correct and a gridview with percentages by topic.

A few simple lines of code would typically handle this:

string listRecipients = ConfigurationManager.AppSettings["candidateTestEmailList"].ToString();
StringBuilder sb = new StringBuilder(2000);
pnlResults.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(sb)));

//---------------------------------------------------------------------
// Send to the mail handler class
//---------------------------------------------------------------------
MailHandler mh = new MailHandler();
mh.SendMail(listRecipients, "Test Results " + tbName.Text, sb.ToString());

But I was getting the error...Gridview must be placed inside a form tag with runat=server. And of course it is, and the panel and the label are not throwing a similar error. I found this nifty fix:

public override void VerifyRenderingInServerForm(Control control)
{ 
return;
}

found it here: http://blogs.x2line.com/al/archive/2004/10/08/576.aspx

Friday, August 20, 2010

Downloading Multiple Files as a Zip File Using GridView and SharpZipLib

Abstract:
Downloading files becomes a painful procedure if you have to select each individual file manually to perform the download. In this article we are going to select multiple files and download all of them as a single zip file. 

Download SharpZipLib: 

SharpZipLib is a free .NET API which is used to perform zipping operations. We will use SharpZipLib to perform the file zip.

Displaying the Files on the GridView Control: 

We have created a folder in our application called "Files" which contains several text files. The first task is to display these files in the GridView control. The implementation is shown below: 



Follow the link :http://www.highoncoding.com/Articles/597_Downloading_Multiple_Files_as_a_Zip_File_Using_GridView_and_SharpZipLib.aspx

Tuesday, May 18, 2010

Check If User Name Exists Using AJAX And C#

Check If User Name Exists Using AJAX And C#

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.

Wednesday, April 28, 2010

Configure Session Time-out (IIS 7)


User Interface

To Use the UI
  1. Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).

  2. In Features View, double-click ASP.






  1. On the ASP page, under Services, expand Session Properties.

  2. In the Time-out field, enter a time-out value in the format hh:mm:ss. For example, enter 00:15:00 for 15 minutes.

  3. In the Actions pane, click Apply.

























Tuesday, April 20, 2010

Display Hierarchical Data with TreeView in ASP.NET 2.0

Check This link


Steps to Create and Deploy SSIS Package as a SQLAgent Job

Microsoft says that SQL Server Integration Services (SSIS) “is a platform for building high performance data integration solutions, including extraction, transformation, and load (ETL) packages for data warehousing.” A simpler way to think of SSIS is that it’s the solution for automating SQL Server. SSISprovides a way to build packages made up of tasks that can move data around from place to place and alter it on the way. There are visual designers (hosted within Business Intelligence Development Studio) to help you build these packages as well as an API for programming SSIS objects from other applications.


as an API for programming SSIS objects from other applications.

Though SSIS is almost infinitely customizable, Microsoft has produced a simple wizard to handle some of the most common ETL tasks: importing data to or exporting data from a SQL Server database. The Import and Export Wizard protects you from the complexity of SSIS while allowing you to move data between any of these data sources:

  • SQL Server databases
  • Flat files
  • Microsoft Access databases
  • Microsoft Excel worksheets
  • Other OLE DB providers

SQL Server 2005 redesigned the way you design data transformation packages. It now includes much more capabilities, and because of that, it features a new tool. It separates the control of the package from the data transformation portion, so you can do much more. For instance, you have the ability to read information from WMIor a web service. There is also the ability to iterate through a loop of data stored in a variable, or from a result set.

Creating a Package

The Import and Export Wizard is easy to use, but it only taps a small part of the functionality of SSIS. To really appreciate the full power of SSIS, you’ll need to use BIDS to build an SSIS package. A package is a collection of SSIS objects including:

  • Connections to data sources.
  • Data flows, which include the sources and destinations that extract and load data, the transformations that modify and extend data, and the paths that link sources, transformations, and destinations.
  • Control flows, which include tasks and containers that execute when the packageruns. You can organize tasks in sequences and in loops.
  • Event handlers, which are workflows that runs in response to the events raised by a package, task, or container.

Step 1: Open SQL Server Business Intelligence Development Studio.

SSIS_SQLAgent_1

Step 2: Create a New Project

SSIS_SQLAgent_2

Step 3: Select Integration Services Project under Business Intelligence Projects and provide a name for the project.

SSIS_SQLAgent_3

Step 4: Add a new Data Source. Right Click on Data Sources and select New Data Source.

SSIS_SQLAgent_4

Step 5: Use the Data Source Wizard to add a new data source. Select ‘Create a data source based on an existing or new connection’ and click on ‘New’.

SSIS_SQLAgent_5

Step 6: Add the Server and Authentication information and click on Test Connection to test the connection. Then click OK.

SSIS_SQLAgent_6

Step 7: A default SSIS package is created under the solution called Package.dtsx. Rename this package with a meaningful name.

SSIS_SQLAgent_7

Step 8: Drag and drop Control Flow Items from the Toolbox on the left to the Control Flow diagram and create the package.

SSIS_SQLAgent_8

Step 9: Double Click on the Data Flow Task to edit each Data Flow and add data transformations.

SSIS_SQLAgent_9

Step 10: Save and Build the package.

SSIS_SQLAgent_10

Step 11: Run the package. On successful completion, the tasks will turn green.

SSIS_SQLAgent_11

Deploying a Package

Step 1: Save a copy of the package on any server.

SSIS_SQLAgent_2_1

Note: If the package is to be deployed on a different server, ensure that the Protection Level is selected as EncryptSensitiveWithPassword

SSIS_SQLAgent_2_2

Provide a Password for the package by clicking on the PackagePassword Item and enter the password.

SSIS_SQLAgent_2_3

Step 2: Select Package location as SQL Server, Server Name as destination server and Authentication Type as Windows Authentication. Click on Package Path to browse and save the package.

SSIS_SQLAgent_2_4

Step 3: Save the package under SSIS Packages.

SSIS_SQLAgent_2_5

Step 4: Open SQL Server Management Studio and connect to the Database Engine on the server where you have saved the Package.

SSIS_SQLAgent_2_6

Step 5: Go to SQL Server Agent -> Job. Right-click and select New Job.

SSIS_SQLAgent_2_7

Step 6: Provide a name for the Job.

SSIS_SQLAgent_2_8

Step 7: Go to Steps and click ‘New’.

SSIS_SQLAgent_2_9

Step 8: Provide a name for the Step and select the Type as SQL Server Integration Services Package.

SSIS_SQLAgent_2_10

Step 9: Select Package Source as SQL Server, Server as the destination server and click on Package to browse and select the package.

SSIS_SQLAgent_2_11

Step 10: Click on data Source tab. Provide a password when prompted (if saved with a password).

SSIS_SQLAgent_2_12

Step 11: Edit the Connection String to add password for OLE DB connections, or change location of Input/Output files if required. Click Ok to save the changes.

SSIS_SQLAgent_2_13

Step 12: Go to Schedules and click New to add a new schedule.

SSIS_SQLAgent_2_14

Step 13: Click Ok on the Job Schedule Properties window to save the schedule.

Step 14: Click Ok on the Job properties window to save the job.


refrence :http://technotes.towardsjob.com/sql-server/steps-to-create-and-deploy-ssis-package-as-a-sqlagent-job/

How to Edit Detailsview in asp.net aplplication

Using template Field you can edit datalist


Check the refrence link

System.Web.HttpException: Request timed out

Summery

executionTimeout
parameter- indicates the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET.

By default, the value of the executionTimeout attribute is set to 90 seconds in theMachine.config file. “Request timed out” error occurs when the processing time of request exceeds 90 seconds. In most cases an error occurs when you are uploading large files.

Solution

To work around this problem, increase the time-out value of request execution.

You can do that by following two ways:

Method 1:
EAUpload component provides a replacement of executionTimeout attribute of httpRuntime config section. If ExecutionTimeout parameter of EAUpload environment is defined then request have time-out that is specified by this parameter and"executionTimeout" parameter of httpRuntime configuration section is ignored. The specified value will take effect only for requests which are processed by EAUpload component. The value that is specified in executionTimeout attribute will be actually for other requests.

Set the ExecutionTimeout parameter value in the EAUpload configuration

  • Open the Web.config file in Notepad.
  • Increase the value of the ExecutionTimeout attribute to avoid time-out errors.
    "1.0" encoding="utf-8" ?>  ...            "3600"                     ...        />              ...       
  • Save the Web.config file.

Method 2:
The executionTimeout attribute exists under httpRequest in the Machine.config file. You can change these settings either in the Web.Config file or in the Machine.config file. The default value for the time-out is 90 seconds. The executionTimeout attribute indicates the maximum number of seconds a request is permitted to run before being shut down by the ASP.NET Web application.

Figure A: Set the executionTimeout attribute value in the Web.config File

  • Open the Web.config file in Notepad.
  • Add the httpRuntime element in the system.web section as follows:
    "1.0" encoding="utf-8" ?>  ...      "90" maxRequestLength="4096" 	useFullyQualifiedRedirectUrl="false" 	minFreeThreads="8" 	minLocalRequestFreeThreads="4" 	appRequestQueueLimit="100" />   ...   
  • Increase the value of the executionTimeout attribute to avoid time-out errors.
  • Save the Web.config file.


Figure B: the executionTimeout attribute value in the Machine.config File
  • Open the Machine.config file in Notepad. The Machine.config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ directory.
  • In the Machine.config file, locate the httpRuntime element.
    "90" maxRequestLength="4096" 	useFullyQualifiedRedirectUrl="false" 	minFreeThreads="8" 	minLocalRequestFreeThreads="4" 	appRequestQueueLimit="100" /> 
  • Increase the value of the executionTimeout attribute to avoid time-out errors.
  • Save the Web.config file.

References:

AjaxToolkit: AutoCompleteExtender

<%@ Register Assembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"%>

Which says that the reference assembly "AjaxControlToolkit.dll" should be registered on the page by using above method. We should also have tagprefix="ajaxToolkit" which is similar to .

In this article I have very simple database table called as "Tbl_Countries" with fields as:

CountryId int primary key,
CountryName varchar(50)

I am using a web service called as "AutoComplete.asmx" whose code behind gets automatically added to the "App_Code" folder.

Note: Very important part is you need to give a reference of "AjaxControlToolkit.dll".

Here is complete code for "AutoComplete.asms.cs".

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

///

/// Summary description for AutoComplete

///

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

public class AutoComplete : System.Web.Services.WebService

{

[WebMethod]

public string[] GetCountriesList(string prefixText)

{

DataSet dtst = new DataSet();

SqlConnection sqlCon = newSqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

string strSql = "SELECT CountryName FROM Tbl_Countries WHERE CountryName LIKE '" + prefixText + "%' ";

SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);

sqlCon.Open();

SqlDataAdapter sqlAdpt = new SqlDataAdapter();

sqlAdpt.SelectCommand = sqlComd;

sqlAdpt.Fill(dtst);

string[] cntName = new string[dtst.Tables[0].Rows.Count];

int i = 0;

try

{

foreach (DataRow rdr in dtst.Tables[0].Rows)

{

cntName.SetValue(rdr["CountryName"].ToString(), i);

i++;

}

}

catch { }

finally

{

sqlCon.Close();

}

return cntName;

}

}

Let us take another page called as "default.aspx" in which I am having a tag and in which a tag in which you can specify path of webservices. You have already registered Assembly="AjaxControlToolkit" on this page so you can use that.


So my entire code will look something like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"%>

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

<title>Untitled Pagetitle>

head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">

<Services>

<asp:ServiceReference Path="AutoComplete.asmx" />

Services>

asp:ScriptManager>

<div>

<asp:TextBox ID="txtCountry" runat="server">asp:TextBox>

<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="txtCountry"ServicePath="AutoComplete.asmx" ServiceMethod="GetCountriesList" MinimumPrefixLength="1" EnableCaching="true" />

div>

form>

body>

html>

Following snapshot gives you clear idea as how the AutoCompleteExtender works.