Aspdotnetcodebook’s Weblog

July 25, 2008

Select a row in an asp:GridView without using a Select Command

Filed under: Uncategorized — aspdotnetcodebook @ 7:33 am


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">   <title>Untitled Page</title></head><body>   <form id="form1" runat="server">       <div>           <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"               Width="200px" AllowPaging="True" OnRowDataBound="PeopleGridView_RowDataBound">               <Columns>                   <asp:BoundField DataField="StringField" HeaderText="Name" SortExpression="StringField">                   </asp:BoundField>               </Columns>           </asp:GridView>       </div>   </form></body></html>

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;

public partial class SelectRow : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            GridView1.DataSource = GetDataSet();            GridView1.DataBind();        }

    }    public DataTable GetDataSet()    {

        DataTable dt = new DataTable("Company");        DataRow dr;        dt.Columns.Add(new DataColumn("Id", typeof(Int32)));        dt.Columns.Add(new DataColumn("IntField", typeof(Int32)));        dt.Columns.Add(new DataColumn("StringField", typeof(string)));        for (int i = 0; i <= 10; i++)        {            dr = dt.NewRow();            dr[0] = i;            dr[1] = i;            dr[2] = "Company" + i + Environment.NewLine + "Title" + i;            dt.Rows.Add(dr);            DataColumn[] Parent_PKColumns = new DataColumn[1];            Parent_PKColumns[0] = dt.Columns["ID"];            dt.PrimaryKey = Parent_PKColumns;            Session["DataSource"] = dt;        }

        return dt;    }    protected void PeopleGridView_RowDataBound(object sender, GridViewRowEventArgs e)    {        if (e.Row.RowType == DataControlRowType.DataRow)        {            e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";

            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);        }

    }}

Return new identity from Strongly Typed Dataset DataTable.Insert method

Filed under: Uncategorized — aspdotnetcodebook @ 7:22 am

Datasets are pretty good at auto generating stored procedures and wrapping c# code around them for you.

However with the insert method you often want to do something with the object that you have just inserted.

Fortunately there is an easy way to get the Sproc and the c# method to return a reference to the object.

Firstly edit your insert stored procedure adding a @return parameter and a line after the insert to set this to a suitable value.

The exmaple below assumes that you are using bigint identity fields.

ALTER PROCEDURE dbo.insMyRow(    @Description varchar(500),    @Return bigint output)AS    SET NOCOUNT OFF;INSERT INTO [myTable] ([Description]) VALUES (@Description);

SET @Return = SCOPE_IDENTITY()

Note that SCOPE_IDENTITY() is similar to @@IDENTITY except its scope is limited to the current command and so improves scalability.

Now when you save the Dataset you see that the insert method takes two parameters, the second being a nullable long.

My first thought was that Datasets should be the end of editing stored procedures but I am still impressed that the c# method declaration changes accordingly.

You can call the updated method in the following way.

long? objId=null;

myTableAdapter d =new myTableAdapter();

d.Insert("Descriptive text", ref objId);

the long? just means nullable long.

After filling the table you can now use the FindByxxxID functions of the DataTable to return the DataRow object.

Building a DAL using Strongly Typed TableAdapters and DataTables in VS 2005 and ASP.NET 2.0

Filed under: Uncategorized — aspdotnetcodebook @ 6:09 am

he word Dataset does not need introduction because it is one of most commonly used object in .net world. So proceeding with this assumption, a typed dataset is an object that derives from Dataset class and additionally it provides strongly typed access to its containing tables and columns. To justify the above line still in depth, to access tables and columns in a dataset we use, check out this link for more details

ADO.NET Tutorial

Filed under: Uncategorized — aspdotnetcodebook @ 5:44 am

DO.NET is a set of computer software components that can be used by programmers to access data and data services. It is a part of the base class library that is included with the Microsoft .NET Framework. It is commonly used by programmers to access and modify data stored in relational database systems, though it can also be used to access data in non-relational sources. ADO.NET is sometimes considered an evolution of ActiveX Data Objects (ADO) technology, but was changed so extensively that it can be conceived of as an entirely new product.
check out this link for more details

July 24, 2008

Three Tier Architecture with ASP.NET

Filed under: Uncategorized — aspdotnetcodebook @ 2:06 pm

Brian Mains talks about the GridView control in the context of 3-tier ASP.NET applications.
Three Tier Architecture with ASP.NET

Load Controls Dynamically in ASP.NET

Filed under: Uncategorized — aspdotnetcodebook @ 2:04 pm

In this article, I will show you one of the ways you can use to handle adding controls dynamically in an ASP.NET Page
Load Controls Dynamically in ASP.NET

How to display a serial number from 1 to n in a grid view

Filed under: Uncategorized — aspdotnetcodebook @ 7:16 am



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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server">     <div>         <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"             PageSize="3" OnPageIndexChanging="GridView1_PageIndexChanging">             <Columns>                 <asp:BoundField DataField="LastName" HeaderText="Name" />                 <asp:BoundField DataField="Lectures" HeaderText="Lectures" />                 <asp:TemplateField HeaderText="S.No">

                     <ItemTemplate>                         <asp:Label ID="Label1" runat="server" Text='<%# (GridView1.PageSize * GridView1.PageIndex) + Container.DisplayIndex + 1 %>'></asp:Label>                     </ItemTemplate>                 </asp:TemplateField>             </Columns>         </asp:GridView>     </div> </form></body></html>

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;

public partial class Paging : System.Web.UI.Page{  protected void Page_Load(object sender, EventArgs e)  {      if (!IsPostBack)      {          GridView1.DataSource = GetDataTable();          GridView1.DataBind();

      }  }  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)  {      GridView1.PageIndex = e.NewPageIndex;

      GridView1.DataSource = GetDataTable();      GridView1.DataBind();  }  private DataTable GetDataTable()  {      //create table      DataTable dt = new DataTable("Members");      dt.Columns.Add("ID", Type.GetType("System.Int32"));      dt.Columns.Add("LastName", Type.GetType("System.String"));      dt.Columns.Add("Lectures", Type.GetType("System.Int32"));

      //create fields      DataColumn[] pk = new DataColumn[1];      pk[0] = dt.Columns["ID"];      dt.PrimaryKey = pk;      dt.Columns["ID"].AutoIncrement = true;      dt.Columns["ID"].AutoIncrementSeed = 1;      dt.Columns["ID"].ReadOnly = true;

      //fill rows      DataRow dr;      for (int x = 1; x <= 10; x++)      {          //make every other one different          if (Math.IEEERemainder(x, 2) == 0)          {              dr = dt.NewRow();              dr["LastName"] = "Riss";              dr["Lectures"] = 14;              dt.Rows.Add(dr);          }          else          {              dr = dt.NewRow();              dr["LastName"] = "Anders";              dr["Lectures"] = 3;              dt.Rows.Add(dr);

          }      }

      return dt;  }}

*

create a template field, in that item template, put a label, specify it’s text as

Text=<%# (GridView1.PageSize * GridView1.PageIndex) + Container.DisplayIndex + 1 %>


July 23, 2008

Export Html to Pdf using iTextSharp(GridView)

Filed under: Uncategorized — aspdotnetcodebook @ 11:39 am


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Untitled Page</title></head><body><form id="form1" runat="server">  <div>      <asp:GridView ID="GridView1" runat="server">      </asp:GridView>      <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Pdf" /></div></form></body></html>


using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using iTextSharp.text;using iTextSharp.text.pdf;using System.IO;using iTextSharp.text.html;

public partial class Pdf : MyPage{protected void Page_Load(object sender, EventArgs e){    if (!IsPostBack)    {        GridView1.DataSource = GetData();        GridView1.DataBind();    }

}protected void Button1_Click(object sender, EventArgs e){    MyPage tmpPage = new MyPage();    HtmlForm form = new HtmlForm();    form.Controls.Add(GridView1);    tmpPage.Controls.Add(form);    StringWriter sw = new StringWriter();    HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);    form.Controls[0].RenderControl(htmlWriter);    string htmlContent = sw.ToString();    Document document = new Document();    // step 2:    // we create a writer that listens to the document    // and directs a PDF-stream to a file    PdfWriter.GetInstance(document, new FileStream("c:\\Chap0101.pdf", FileMode.Create));

    // step 3: we open the document    document.Open();

    // step 4: we add a paragraph to the document    //document.Add(new Paragraph(htmlContent.ToString()));

    System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(new StringReader(htmlContent));

    HtmlParser.Parse(document, _xmlr);

    // step 5: we close the document    document.Close();

    ShowPdf("c:\\Chap0101.pdf");

}

private void ShowPdf(string s){    Response.ClearContent();    Response.ClearHeaders();    Response.AddHeader("Content-Disposition", "inline;filename=" + s);    Response.ContentType = "application/pdf";    Response.WriteFile(s);    Response.Flush();    Response.Clear();}public DataSet GetData(){    DataSet ds = new DataSet();    DataTable dt = new DataTable("Product");    DataRow dr;    dt.Columns.Add(new DataColumn("Price", typeof(Int32)));    dt.Columns.Add(new DataColumn("DisCount", typeof(Int32)));    dt.Columns.Add(new DataColumn("SellPrice", typeof(Int32)));    for (int i = 1; i <= 10; i++)    {        dr = dt.NewRow();        dr[0] = i;        dr[1] = i * 2;        dr[2] = 1 * 3;        dt.Rows.Add(dr);    }    ds.Tables.Add(dt);    Session["dt"] = dt;    return ds;}}

*Create a new clas Mypage.cs in app_code folder.

using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;

/// <summary>/// Summary description for MyPage/// </summary>public class MyPage : Page{ public override void VerifyRenderingInServerForm(Control control) {     GridView grid = control as GridView;     if (grid != null && grid.ID == "GridView1")         return;     else         base.VerifyRenderingInServerForm(control);

 }}

How to add an RSS feed to your website

Filed under: Uncategorized — aspdotnetcodebook @ 5:08 am








Many websites have RSS feeds, especially websites with blogs. An RSS feed identifies content on your website, including the publication date. Web browsers and blog readers use the RSS feed to notify users when content is updated.

The acronym RSS stands for “really simple syndication”, and the “really simple” part is no exaggeration. Thanks to the simplicity of RSS it’s very easy to add an RSS feed to your website. You can read about the RSS specification here.

Here’s what my RSS feed looks like. Pretty simple, eh?

Step 1: Create an .aspx page (e.g. rss.aspx) that returns information about your content in RSS format. This .aspx page will return data in XML format, not HTML. I recommend using output caching on this page since it’s likely to be retrieved frequently. I cache my rss feed for one minute:


<%@ OutputCache Duration="60" VaryByParam="none" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="rss.aspx.cs" Inherits="rss" %>

In the code-behind for the .aspx page, just build your RSS data and output it with Response.Write.

For example, here’s my code-behind. The code first calls a dummy Data Method to get all the data about my blog. The data is stored in a dataset. Then the code iterates through each row in the dataset and builds the section of the RSS XML. Finally, the items are inserted into the XML and the XML is output using Response.Write():

Step 2: Now that you have a .aspx page that returns your RSS data, you need to notify web browsers and blog readers that the feed exists. Just add a tag to the section of your .aspx pages. For example, here’s my tag:


<head runat="server">
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.aspx" runat="server" id="rss_link" visible="false" />

<title>Untitled Page</title>
</head>

check out this complete code


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Rss.aspx.cs" Inherits="Rss" %>
<%@ OutputCache Duration="60" VaryByParam="none" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.aspx" runat="server" id="rss_link" visible="false" />

<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Rss : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {

     rss_link.Visible = true;

     if (!IsPostBack)
     {
         DataTable entriesDataSet = new DataTable();
         entriesDataSet = Data();

         const string itemFormat =
 @"
 <item>
   <title>{0}</title>
   <link>{1}</link>
   <description>{2}</description>
   <pubDate>{3}</pubDate>
 </item>";

         string items = string.Empty;

         foreach (DataRow row in entriesDataSet.Rows)
         {
             string url = string.Format("http://localhost/MyPractice/Rss.aspx?b={0}", row["ID"]);
             DateTime pubDate = (DateTime)row["TimeStamp"];

             string item = string.Format(itemFormat, row["Title"], url, row["Title"], pubDate.ToString("s"));

             items = item + items;
         }

         const string rssFormatString =
 @"<rss version=""2.0"">
<!-- generated {0} -->
<channel>
 <title>xyz</title>
 <link>http://aspdotnetcodebook.blogspot.com</link>
 <description>by xyz</description>
 {1}
</channel>
</rss>";

         string result = string.Format(rssFormatString, DateTime.Now, items);

         Response.Clear();
         Response.BufferOutput = true;
         Response.ContentType = "text/xml";
         Response.StatusCode = 200;

         Response.Write(result);
         Response.End();
     }
 }

 public DataTable Data()
 {

     DataTable dt = new DataTable();
     dt.Columns.Add("Id", typeof(int));
     dt.Columns.Add("Title", typeof(string));
     dt.Columns.Add("link", typeof(string));
     dt.Columns.Add("description", typeof(string));
     dt.Columns.Add("TimeStamp", typeof(DateTime));

     dt.Rows.Add(new object[] { "1", "test", "http://abc.com ", "test", "12/12/2008" });
     dt.Rows.Add(new object[] { "2", "test", "http://abc.com ", "test", "12/12/2008" });
     dt.Rows.Add(new object[] { "3", "test", "http://abc.com ", "test", "12/12/2008" });

     return dt;
 }
}

How To Create A Filebrowser in ASP

Filed under: Uncategorized — aspdotnetcodebook @ 4:34 am


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">  <title>Untitled Page</title></head><body>  <form id="form1" runat="server">      <div>          <h1 class="boxes">              Files on the Server:              <asp:Literal ID="litLocation" runat="server" />          </h1>          <asp:Panel ID="panFiles" runat="server" CssClass="boxes">              <asp:PlaceHolder ID="myPlaceHolder" runat="server" />          </asp:Panel>          <asp:Panel ID="Panel1" runat="server" CssClass="boxes">              <asp:TextBox ID="txtFolder" runat="server"></asp:TextBox>              <asp:Button ID="btnNewFolder" runat="server" Text="Create New Folder" OnClick="btnNewFolder_Click" />          </asp:Panel>          <asp:Panel ID="panUpload" runat="server" CssClass="boxes">              Choose a file to upload to the server<br />              <asp:FileUpload ID="fupTest" runat="server" Width="400px" />              <br />              <asp:Button ID="btnUpload" runat="server" Text="Upload File" OnClick="btnUpload_Click" />              <p>                  <asp:Label ID="labMessage" runat="server"></asp:Label>              </p>          </asp:Panel>      </div>  </form></body></html>

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.IO;

public partial class FileBrowser : System.Web.UI.Page{   protected void Page_Load(object sender, EventArgs e)   {       string currentRoot = RetrievePathOfFolderToDisplay();       litLocation.Text = currentRoot;       GenerateListing(currentRoot);   }   /// <summary>   /// Displays the content of the specified folder.   /// </summary>   private void GenerateListing(string rootpath)   {       // First clear out the place holder       myPlaceHolder.Controls.Clear();       // Calculate the path to retrieve folders + files       string path = Server.MapPath("") + "/" + rootpath;       // Make the "go up a level" link if needed       MakeUpOneLevelLink(rootpath);       // Get a list of all folders       DirectoryInfo dirInfo = new DirectoryInfo(path);       DirectoryInfo[] folders = dirInfo.GetDirectories();       // Loop through each folder and display it       foreach (DirectoryInfo folder in folders)       {           DisplayFolder(folder, rootpath);       }       // Get a list of all the files in current path       FileInfo[] files = dirInfo.GetFiles();       // Loop through each file       foreach (FileInfo file in files)       {           DisplayFile(file, rootpath);       }   }   /// <summary>   /// Retrieves the path of the folder to be displayed   /// </summary>   ///    private string RetrievePathOfFolderToDisplay()   {       string localpath = Request.QueryString["local"];       // If no query string, use uploads folder as the root       if (localpath == null)           return "uploads";       else           // Remove the URL encoding necessary for           // the querystring           return Server.UrlDecode(localpath);   }   /// <summary>   /// Displays the appropriate controls for the passed folder   /// </summary>   private void DisplayFolder(DirectoryInfo folder, string rootpath)   {       // Get the folder name without the path       string shortfolder = Path.GetFileName(folder.FullName);       // Add a folder icon       Image img = new Image();       img.ImageUrl = "images/mime_folder.png";       myPlaceHolder.Controls.Add(img);       // Add a nonbreakable space       LiteralControl space1 = new LiteralControl("&nbsp;");       myPlaceHolder.Controls.Add(space1);       // Add a link to the folder so user can display it       HyperLink lnk = new HyperLink();       lnk.Text = shortfolder;       // The link for the folder must pass the folder name.       // Because the folder name may contain characters that are       // not allowed in a querystring, we must URL encode it       lnk.NavigateUrl = "FileBrowser.aspx?local=" +       Server.UrlEncode(rootpath + "/" + shortfolder);       myPlaceHolder.Controls.Add(lnk);       // Add a line break       LiteralControl br1 = new LiteralControl("<br/>");       myPlaceHolder.Controls.Add(br1);   }   /// <summary>   /// Displays the appropriate controls for the passed file   /// </summary>   private void DisplayFile(FileInfo file, string rootpath)   {// Get the filename without the path       string shortname = Path.GetFileName(file.FullName);       // Add a file icon       Image img = new Image();       img.ImageUrl = GetIconForExtension(file);       myPlaceHolder.Controls.Add(img);       // Add a nonbreakable space       LiteralControl space2 = new LiteralControl("&nbsp;");       myPlaceHolder.Controls.Add(space2);       // Add a link to the file so user can download/view it       HyperLink lnk = new HyperLink();       lnk.Text = shortname;       lnk.NavigateUrl = Server.UrlDecode(rootpath) + "/" +       shortname;       myPlaceHolder.Controls.Add(lnk);       // Add the file size in kb       long kb = file.Length / 1000;       LiteralControl size = new LiteralControl(" [" + kb +       " KB]");       myPlaceHolder.Controls.Add(size);       // Add a line break       LiteralControl br2 = new LiteralControl("<br/>");       myPlaceHolder.Controls.Add(br2);   }   /// <summary>   /// Returns the filename of the appropriate icon image file   /// based on the extension of the passed file   /// </summary>   private string GetIconForExtension(FileInfo file)   {       string image = "images/";       string ext = Path.GetExtension(file.FullName).ToLower();       if (ext == ".txt")           image += "mime_text.png";       else if (ext == ".doc")           image += "mime_doc.png";       else if (ext == ".pdf")           image += "mime_pdf.png";       else if (ext == ".gif" || ext == ".jpg" || ext == ".wmf")           image += "mime_image.gif";       else if (ext == ".html" || ext == ".htm")

           image += "mime_html.gif";       else           image += "mime_unknown.png";       return image;   }   /// <summary>   /// Makes the "go up a level" link (if needed for the   /// current folder) and adds it to the place holder   /// </summary>   private void MakeUpOneLevelLink(string currentFolder)   {       // Get the previous folder (the next one "up" in       // the hierarchy)       string previousFolder = GetPreviousFolder(currentFolder);       // If there is a previous path, add a link to       // place holder       if (previousFolder != "")       {           Image imgBack = new Image();           imgBack.ImageUrl = "images/mime_folder.gif";           myPlaceHolder.Controls.Add(imgBack);           HyperLink lnkBack = new HyperLink();           lnkBack.Text = "..";           lnkBack.NavigateUrl = "FileBrowser.aspx?local=" +           Server.UrlEncode(previousFolder);           myPlaceHolder.Controls.Add(lnkBack);           LiteralControl br = new LiteralControl("<br/>");           myPlaceHolder.Controls.Add(br);       }   }   /// <summary>   /// Gets the previous folder (the next one "up" in the file   /// system hierarchy) from the passed path.   /// If there was no previous folder, return an   /// empty string   /// </summary>   private string GetPreviousFolder(string path)   {       int posOfLastSlash = path.LastIndexOf("/");       if (posOfLastSlash < 0)           return "";       string stripped = path.Remove(posOfLastSlash);       return stripped;   }   /// <summary>   /// Event handler for the upload button for the FileUploader   /// </summary>   protected void btnUpload_Click(object sender, EventArgs e)   {       // The location for the uploaded file is current path       string path = RetrievePathOfFolderToDisplay();       if (fupTest.HasFile)       {           string fullname = Server.MapPath(path + "/" +           fupTest.FileName);           if (System.IO.File.Exists(fullname))           {               labMessage.Text =               "File already exists - uploaded cancelled";           }           else           {               fupTest.SaveAs(fullname);               labMessage.Text = "File successfully uploaded";               // Recreate the file listing to show the               // uploaded file               GenerateListing(path);           }       }       else       {           labMessage.Text = "File was not specified";       }   }   /// <summary>   /// Event handler for the create new folder button   /// </summary>   protected void btnNewFolder_Click(object sender, EventArgs e)   {       // Get the location for the new folder       string folderLocation = RetrievePathOfFolderToDisplay();       string fullPath = Server.MapPath(folderLocation) + "/" +       txtFolder.Text;       // Create the folder on the server       Directory.CreateDirectory(fullPath);       // Recreate the file listing to show the new folder       GenerateListing(folderLocation);   }

}
Older Posts »

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.