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");