<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Thinking to Action</title>
	<atom:link href="http://thinhhq.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinhhq.wordpress.com</link>
	<description>Thinking to Action</description>
	<lastBuildDate>Sat, 06 Sep 2008 11:32:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='thinhhq.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Thinking to Action</title>
		<link>http://thinhhq.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://thinhhq.wordpress.com/osd.xml" title="Thinking to Action" />
	<atom:link rel='hub' href='http://thinhhq.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Upload large files with asp.net</title>
		<link>http://thinhhq.wordpress.com/2008/09/06/upload-large-files-with-aspnet/</link>
		<comments>http://thinhhq.wordpress.com/2008/09/06/upload-large-files-with-aspnet/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 11:25:52 +0000</pubDate>
		<dc:creator>thinhhq</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://thinhhq.wordpress.com/?p=12</guid>
		<description><![CDATA[When I try to find a solution for uploading large files in ASP.NET I&#8217;ve found a component met my requirement. It&#8217;s PowerUpload but this is not a free component. Fortunately, when I read the book ASP.NET 3.5 Unleashed I&#8217;ve found another solution in this book. Thank to Stephen Walther  and his solution. This solution apply [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thinhhq.wordpress.com&amp;blog=1429123&amp;post=12&amp;subd=thinhhq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="line-height:14.25pt;"><span style="font-family:&quot;">When I try to find a solution for uploading large files in ASP.NET I&#8217;ve found a component met my requirement. It&#8217;s PowerUpload but this is not a free component. Fortunately, when I read the book ASP.NET 3.5 Unleashed I&#8217;ve found another solution in this book. Thank to Stephen Walther  and his solution. This solution apply for ASP.NET 2.0 and 3.5. I&#8217;ve also tried with ASP.NET 1.1 and it is ok.</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">Here&#8217;s the source code :</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">In the web.config you put the key httpRuntime and specify maxRequestLength up to 100 MB, requestLengthDiskThreshold is the buffer size for ASP.NET framework read each chunk of byte from uploaded file. Note that requestLengthDiskThreshold is not available with ASP.NET 1.1</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">For ASP.NET 2.0 and above :</span></p>
<p style="line-height:14.25pt;"><span style="color:#0000ff;"><span style="font-family:&quot;">&lt;</span><span style="font-family:&quot;">httpRuntime</span><span style="font-family:&quot;"> </span><span style="font-family:&quot;">maxRequestLength</span><span style="font-family:&quot;">=</span><span style="font-family:&quot;">&#8220;</span><span style="font-family:&quot;">102400</span><span style="font-family:&quot;">&#8220;</span><span style="font-family:&quot;"> </span><span style="font-family:&quot;">requestLengthDiskThreshold</span><span style="font-family:&quot;">=</span><span style="font-family:&quot;">&#8220;</span><span style="font-family:&quot;">100</span><span style="font-family:&quot;">&#8220;</span><span style="font-family:&quot;">/&gt;</span></span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">For ASP.NET 1.1 :</span></p>
<p style="line-height:14.25pt;"><span style="color:#0000ff;"><span style="font-family:&quot;"> &lt;</span><span style="font-family:&quot;">httpRuntime</span><span style="font-family:&quot;"> </span><span style="font-family:&quot;">maxRequestLength</span><span style="font-family:&quot;">=</span><span style="font-family:&quot;">&#8220;</span><span style="font-family:&quot;">102400</span><span style="font-family:&quot;">&#8220;</span><span style="font-family:&quot;"> /&gt;</span></span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;"> </span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">Create an upload page :</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;color:#0000ff;">WebForm1.aspx :</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">&lt;%@ Page language=&#8221;c#&#8221; Codebehind=&#8221;WebForm1.aspx.cs&#8221; AutoEventWireup=&#8221;false&#8221; Inherits=&#8221;LargeFileUpload.WebForm1&#8243; %&gt;<br />
&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.0 Transitional//EN&#8221; &gt;<br />
&lt;HTML&gt;<br />
 &lt;HEAD&gt;<br />
  &lt;title&gt;WebForm1&lt;/title&gt;<br />
  &lt;meta name=&#8221;GENERATOR&#8221; Content=&#8221;Microsoft Visual Studio .NET 7.1&#8243;&gt;<br />
  &lt;meta name=&#8221;CODE_LANGUAGE&#8221; Content=&#8221;C#&#8221;&gt;<br />
  &lt;meta name=&#8221;vs_defaultClientScript&#8221; content=&#8221;JavaScript&#8221;&gt;<br />
  &lt;meta name=&#8221;vs_targetSchema&#8221; content=&#8221;<a href="http://schemas.microsoft.com/intellisense/ie5">http://schemas.microsoft.com/intellisense/ie5</a>&#8220;&gt;<br />
 &lt;/HEAD&gt;<br />
 &lt;body MS_POSITIONING=&#8221;GridLayout&#8221;&gt;<br />
  &lt;form id=&#8221;Form1&#8243; method=&#8221;post&#8221; runat=&#8221;server&#8221;&gt;<br />
   &lt;INPUT type=&#8221;file&#8221; id=&#8221;fuAttachment&#8221; runat=&#8221;server&#8221;/&gt;<br />
   &lt;br/&gt;<br />
   &lt;asp:Button id=&#8221;btnSave&#8221; runat=&#8221;server&#8221;<br />
    Text=&#8221;Save&#8221;&gt;&lt;/asp:Button&gt;<br />
   &lt;br/&gt;<br />
   &lt;asp:Repeater id=&#8221;rptListFiles&#8221; runat=&#8221;server&#8221;&gt;<br />
    &lt;HeaderTemplate&gt;<br />
     &lt;table border=&#8221;1&#8243;&gt;<br />
      &lt;tr&gt;<br />
       &lt;th&gt;ID&lt;/th&gt;       <br />
       &lt;th&gt;File Name&lt;/th&gt;<br />
       &lt;th&gt;File Size (bytes)&lt;/th&gt;<br />
      &lt;/tr&gt;<br />
    &lt;/HeaderTemplate&gt;<br />
    &lt;ItemTemplate&gt;<br />
     &lt;tr&gt;<br />
      &lt;td&gt;<br />
       &lt;%#DataBinder.Eval(Container.DataItem,&#8221;Id&#8221;)%&gt;<br />
      &lt;/td&gt;<br />
      &lt;td&gt;<br />
       &lt;a href=&#8217;FileDownload.aspx?ID=&lt;%#DataBinder.Eval(Container.DataItem,&#8221;Id&#8221;)%&gt;&amp;FileName=&lt;%#DataBinder.Eval(Container.DataItem,&#8221;FileName&#8221;)%&gt;&#8217;&gt;&lt;%#DataBinder.Eval(Container.DataItem,&#8221;FileName&#8221;)%&gt;&lt;/a&gt;<br />
      &lt;/td&gt;<br />
      &lt;td&gt;<br />
       &lt;%#DataBinder.Eval(Container.DataItem,&#8221;FileSize&#8221;)%&gt;<br />
      &lt;/td&gt;<br />
     &lt;/tr&gt;<br />
    &lt;/ItemTemplate&gt;<br />
    &lt;AlternatingItemTemplate&gt;<br />
     &lt;tr&gt;<br />
      &lt;td&gt;<br />
       &lt;%#DataBinder.Eval(Container.DataItem,&#8221;Id&#8221;)%&gt;<br />
      &lt;/td&gt;<br />
      &lt;td&gt;<br />
       &lt;a href=&#8217;FileDownload.aspx?ID=&lt;%#DataBinder.Eval(Container.DataItem,&#8221;Id&#8221;)%&gt;&amp;FileName=&lt;%#DataBinder.Eval(Container.DataItem,&#8221;FileName&#8221;)%&gt;&#8217; target=&#8221;_blank&#8221;&gt;&lt;%#DataBinder.Eval(Container.DataItem,&#8221;FileName&#8221;)%&gt;&lt;/a&gt;<br />
      &lt;/td&gt;<br />
      &lt;td&gt;<br />
       &lt;%#DataBinder.Eval(Container.DataItem,&#8221;FileSize&#8221;)%&gt;<br />
      &lt;/td&gt;<br />
     &lt;/tr&gt;<br />
    &lt;/AlternatingItemTemplate&gt;<br />
    &lt;FooterTemplate&gt;<br />
     &lt;/table&gt;<br />
    &lt;/FooterTemplate&gt;<br />
   &lt;/asp:Repeater&gt;<br />
  &lt;/form&gt;<br />
 &lt;/body&gt;<br />
&lt;/HTML&gt;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;color:#0000ff;">WebForm1.aspx.cs :</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Configuration;<br />
using System.IO;<br />
using System.Drawing;<br />
using System.Web;<br />
using System.Web.SessionState;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.HtmlControls;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">namespace LargeFileUpload<br />
{<br />
 /// &lt;summary&gt;<br />
 /// Summary description for WebForm1.<br />
 /// &lt;/summary&gt;<br />
 public class WebForm1 : System.Web.UI.Page<br />
 {<br />
  protected System.Web.UI.WebControls.Button btnSave;<br />
  protected System.Web.UI.WebControls.Repeater rptListFiles;<br />
  protected System.Web.UI.HtmlControls.HtmlInputFile fuAttachment;<br />
  private string strConString;<br />
 <br />
  private void Page_Load(object sender, System.EventArgs e)<br />
  {<br />
   strConString = ConfigurationSettings.AppSettings["UnleashDBConnString"];</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   if(!IsPostBack)<br />
   {    <br />
    LoadFileList();    <br />
   }<br />
  }</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">  #region Web Form Designer generated code<br />
  override protected void OnInit(EventArgs e)<br />
  {<br />
   //<br />
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.<br />
   //<br />
   InitializeComponent();<br />
   base.OnInit(e);<br />
  }<br />
  <br />
  /// &lt;summary&gt;<br />
  /// Required method for Designer support &#8211; do not modify<br />
  /// the contents of this method with the code editor.<br />
  /// &lt;/summary&gt;<br />
  private void InitializeComponent()<br />
  {   <br />
   this.btnSave.Click += new System.EventHandler(this.btnSave_Click);<br />
   this.Load += new System.EventHandler(this.Page_Load);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">  }<br />
  #endregion</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">  private void btnSave_Click(object sender, System.EventArgs e)<br />
  {<br />
   if (fuAttachment.PostedFile == null)<br />
    return;<br />
      <br />
   SqlConnection con = new SqlConnection(strConString);<br />
               <br />
   using (con)<br />
   {<br />
    con.Open();<br />
    int id = InsertFile(con, GetFileNameFromFullFileName(fuAttachment.PostedFile.FileName));<br />
    if(id &gt; 0)<br />
     StoreFile(con, id, fuAttachment.PostedFile.InputStream);<br />
   }</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   LoadFileList();<br />
  }</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">  private string GetFileNameFromFullFileName(string strFullFileName)<br />
  {<br />
   if(string.Empty.Equals(strFullFileName))<br />
    return string.Empty;<br />
   string strFileName = string.Empty;<br />
   int iPos = strFullFileName.LastIndexOf(&#8220;\\&#8221;);<br />
   if(iPos &gt; -1)<br />
    return strFullFileName.Substring(iPos + 1);<br />
   return string.Empty;<br />
  }</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">  private int InsertFile(SqlConnection con, string fileName)<br />
  {<br />
   // parse file name with asp.net 1.1<br />
   <br />
   string strInsertCommand = @&#8221;<br />
                                    INSERT INTO Attachment(FileName) VALUES(@fileName)<br />
                                    SELECT @id = SCOPE_IDENTITY()<br />
                                   &#8220;;<br />
   SqlCommand cmd = new SqlCommand();<br />
       <br />
   cmd.CommandText = strInsertCommand;<br />
   cmd.Connection = con;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   cmd.Parameters.Add(new SqlParameter());<br />
   cmd.Parameters.Add(new SqlParameter());<br />
   <br />
   cmd.Parameters[0].ParameterName = &#8220;@fileName&#8221;;<br />
   cmd.Parameters[0].Size = 50;   <br />
   cmd.Parameters[0].Value = fileName;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   cmd.Parameters[1].ParameterName = &#8220;@id&#8221;;<br />
   cmd.Parameters[1].Size = 4;<br />
   cmd.Parameters[1].Direction = ParameterDirection.Output;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   cmd.ExecuteNonQuery();<br />
   if (cmd.Parameters[1].Value != DBNull.Value)<br />
    return Convert.ToInt32(cmd.Parameters[1].Value);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   return 0;<br />
  }</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">  private void StoreFile(SqlConnection con,int id, Stream byteStream)<br />
  {<br />
   int iBufferLength = 8040;<br />
   // Step 1 update first byte stream<br />
   string strUpdateCommandStep1 = @&#8221;UPDATE Attachment Set <a href="mailto:FileContent=@fileContent">FileContent=@fileContent</a> Where ID = @id&#8221;;<br />
   SqlCommand cmdStep1 = new SqlCommand();</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   cmdStep1.CommandText = strUpdateCommandStep1;<br />
   cmdStep1.Connection = con;<br />
       <br />
   BinaryReader br = new BinaryReader(byteStream);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   byte[] buffer = br.ReadBytes(iBufferLength);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   bool isContinue = true;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   if (buffer != null)<br />
   {<br />
    cmdStep1.Parameters.Add(new SqlParameter());<br />
    cmdStep1.Parameters.Add(new SqlParameter());</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">    cmdStep1.Parameters[0].ParameterName = &#8220;@fileContent&#8221;;<br />
    cmdStep1.Parameters[0].Value = buffer;<br />
    cmdStep1.Parameters[0].Size = iBufferLength;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">    cmdStep1.Parameters[1].ParameterName = &#8220;@id&#8221;;<br />
    cmdStep1.Parameters[1].SqlDbType = SqlDbType.Int;<br />
    cmdStep1.Parameters[1].Size = 4;<br />
    cmdStep1.Parameters[1].Value = id;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">    cmdStep1.ExecuteNonQuery();<br />
   }<br />
   else<br />
   {<br />
    isContinue = false;<br />
   }</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   if (!isContinue)<br />
    return;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   // Step 2 continue read from byte stream and update to database<br />
   string strUpdateCommandStep2 = &#8220;UPDATE Attachment Set FileContent.Write(@buffer, null, 0) Where ID = @id &#8220;;<br />
   SqlCommand cmdStep2 = new SqlCommand();<br />
       <br />
   cmdStep2.Connection = con;<br />
   cmdStep2.CommandText = strUpdateCommandStep2;<br />
   cmdStep2.Parameters.Add(new SqlParameter());<br />
   cmdStep2.Parameters.Add(new SqlParameter());<br />
       <br />
   cmdStep2.Parameters[0].ParameterName = &#8220;@buffer&#8221;;<br />
   cmdStep2.Parameters[0].SqlDbType = SqlDbType.VarBinary;<br />
   cmdStep2.Parameters[0].Size = iBufferLength;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   cmdStep2.Parameters[1].ParameterName = &#8220;@id&#8221;;<br />
   cmdStep2.Parameters[1].SqlDbType = SqlDbType.Int;<br />
   cmdStep2.Parameters[1].Size = 4;<br />
   cmdStep2.Parameters[1].Value = id;        </span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   buffer = br.ReadBytes(iBufferLength);<br />
   while (buffer.Length &gt; 0)<br />
   {           <br />
    cmdStep2.Parameters[0].Value = buffer;<br />
           <br />
    cmdStep2.ExecuteNonQuery();</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">    buffer = br.ReadBytes(iBufferLength);<br />
   }</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   br.Close();<br />
  }   <br />
  private void LoadFileList()<br />
  {<br />
   SqlConnection con = new SqlConnection(strConString);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   using(con)<br />
   {<br />
    SqlCommand cmd  = con.CreateCommand();<br />
    cmd.CommandText = @&#8221;SELECT<br />
          Id, FileName, FileContent, DATALENGTH(FileContent) As FileSize<br />
         From Attachment&#8221;;         </span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">    SqlDataAdapter da = new SqlDataAdapter(cmd);<br />
    con.Open();<br />
    DataTable dtb = new DataTable();<br />
    da.Fill(dtb);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">    if(dtb != null)<br />
    {<br />
     rptListFiles.DataSource = dtb;<br />
     rptListFiles.DataBind();<br />
    }<br />
   }<br />
  }<br />
 }<br />
}</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;"> </span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;color:#0000ff;">FileDownLoad.aspx :</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">&lt;%@ Page language=&#8221;c#&#8221; Codebehind=&#8221;FileDownload.aspx.cs&#8221; AutoEventWireup=&#8221;false&#8221; Inherits=&#8221;LargeFileUpload.FileDownload&#8221; %&gt;<br />
&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.0 Transitional//EN&#8221; &gt; </span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">&lt;html&gt;<br />
  &lt;head&gt;<br />
    &lt;title&gt;FileDownload&lt;/title&gt;<br />
    &lt;meta name=&#8221;GENERATOR&#8221; Content=&#8221;Microsoft Visual Studio .NET 7.1&#8243;&gt;<br />
    &lt;meta name=&#8221;CODE_LANGUAGE&#8221; Content=&#8221;C#&#8221;&gt;<br />
    &lt;meta name=vs_defaultClientScript content=&#8221;JavaScript&#8221;&gt;<br />
    &lt;meta name=vs_targetSchema content=&#8221;<a href="http://schemas.microsoft.com/intellisense/ie5">http://schemas.microsoft.com/intellisense/ie5</a>&#8220;&gt;<br />
  &lt;/head&gt;<br />
  &lt;body MS_POSITIONING=&#8221;GridLayout&#8221;&gt;<br />
 <br />
    &lt;form id=&#8221;Form1&#8243; method=&#8221;post&#8221; runat=&#8221;server&#8221;&gt;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">     &lt;/form&gt;<br />
 <br />
  &lt;/body&gt;<br />
&lt;/html&gt;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;color:#0000ff;">FileDownload.aspx.cs :</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Configuration;<br />
using System.IO;<br />
using System.Drawing;<br />
using System.Web;<br />
using System.Web.SessionState;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.HtmlControls;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">namespace LargeFileUpload<br />
{<br />
 /// &lt;summary&gt;<br />
 /// Summary description for FileDownload.<br />
 /// &lt;/summary&gt;<br />
 public class FileDownload : System.Web.UI.Page<br />
 {<br />
  private void Page_Load(object sender, System.EventArgs e)<br />
  {<br />
   if(!IsPostBack)<br />
   {<br />
    DownloadFile();<br />
   }<br />
  }</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">  #region Web Form Designer generated code<br />
  override protected void OnInit(EventArgs e)<br />
  {<br />
   //<br />
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.<br />
   //<br />
   InitializeComponent();<br />
   base.OnInit(e);<br />
  }<br />
  <br />
  /// &lt;summary&gt;<br />
  /// Required method for Designer support &#8211; do not modify<br />
  /// the contents of this method with the code editor.<br />
  /// &lt;/summary&gt;<br />
  private void InitializeComponent()<br />
  {   <br />
   this.Load += new System.EventHandler(this.Page_Load);<br />
  }<br />
  #endregion</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">  private void DownloadFile()<br />
  {<br />
   System.Web.HttpContext context = System.Web.HttpContext.Current;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   if (string.Empty.Equals((context.Request["ID"])))<br />
    return;<br />
   int id = Convert.ToInt32(context.Request["ID"]);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   if (string.Empty.Equals((context.Request["FileName"])))<br />
    return;<br />
   string strFileName = context.Request["FileName"];</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   context.Response.Buffer = false;<br />
   context.Response.AddHeader(&#8220;Content-disposition&#8221;, string.Format(&#8220;attachment; filename={0}&#8221;, strFileName));<br />
   context.Response.ContentType = &#8220;application/octet-stream&#8221;;<br />
       <br />
   string strCommandText = &#8220;Select FileContent From Attachment Where Id = @id&#8221;;<br />
   string strConnString = System.Configuration.ConfigurationSettings.AppSettings["UnleashDBConnString"];</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   SqlConnection con = new SqlConnection(strConnString);<br />
   SqlCommand cmd = new SqlCommand();<br />
   cmd.CommandText = strCommandText;<br />
   cmd.Connection = con;<br />
       <br />
   cmd.Parameters.Add(new SqlParameter());<br />
   cmd.Parameters[0].ParameterName = &#8220;@id&#8221;;<br />
   cmd.Parameters[0].SqlDbType = SqlDbType.Int;<br />
   cmd.Parameters[0].Size = 4;<br />
   cmd.Parameters[0].Value = id;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">   using (con)<br />
   {<br />
    con.Open();<br />
    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">    if (reader.Read())<br />
    {                            <br />
     int iBufferLength = 8040;<br />
     byte[] chunk = new byte[iBufferLength];<br />
     long iReturnCount = 0;<br />
     long iStartIndex = 0;<br />
     iReturnCount = reader.GetBytes(0, iStartIndex, chunk, 0, iBufferLength);</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">     while (iReturnCount == iBufferLength)<br />
     {<br />
      context.Response.BinaryWrite(chunk);<br />
      iStartIndex += iBufferLength;</span></p>
<p style="line-height:14.25pt;"><span style="font-family:&quot;">      iReturnCount = reader.GetBytes(0, iStartIndex, chunk, 0, iBufferLength);<br />
     }<br />
               <br />
     // read remain byte from stream<br />
     byte[] actualChunk = new byte[iReturnCount - 1];<br />
     Array.Copy(chunk,0,actualChunk,0,(int)iReturnCount &#8211; 1);     <br />
     context.Response.BinaryWrite(actualChunk);<br />
    }                      <br />
   }<br />
  }<br />
 }<br />
}</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-family:Calibri;font-size:small;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-family:Calibri;color:#0000ff;font-size:small;">The database use for this demo has one table Attachment :</span></p>
<table class="MsoTableGrid" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;width:159.6pt;border:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">Column Name</span></p>
</td>
<td style="border-bottom:black 1pt solid;border-left:#ece9d8;background-color:transparent;width:159.6pt;border-top:black 1pt solid;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">Data Type</span></p>
</td>
<td style="border-bottom:black 1pt solid;border-left:#ece9d8;background-color:transparent;width:159.6pt;border-top:black 1pt solid;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">Allow Nulls</span></p>
</td>
</tr>
<tr>
<td style="border-bottom:black 1pt solid;border-left:black 1pt solid;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">Id</span></p>
</td>
<td style="border-bottom:black 1pt solid;border-left:#ece9d8;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">Int (identity)</span></p>
</td>
<td style="border-bottom:black 1pt solid;border-left:#ece9d8;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;"> </span></p>
</td>
</tr>
<tr>
<td style="border-bottom:black 1pt solid;border-left:black 1pt solid;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">FileName</span></p>
</td>
<td style="border-bottom:black 1pt solid;border-left:#ece9d8;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">Nvarchar(50)</span></p>
</td>
<td style="border-bottom:black 1pt solid;border-left:#ece9d8;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;"> </span></p>
</td>
</tr>
<tr>
<td style="border-bottom:black 1pt solid;border-left:black 1pt solid;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">FileContent</span></p>
</td>
<td style="border-bottom:black 1pt solid;border-left:#ece9d8;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">VarBinary(MAX)</span></p>
</td>
<td style="border-bottom:black 1pt solid;border-left:#ece9d8;background-color:transparent;width:159.6pt;border-top:#ece9d8;border-right:black 1pt solid;padding:0 5.4pt;" width="213" valign="top">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-family:Calibri;font-size:small;">yes</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-family:Calibri;font-size:small;"> </span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thinhhq.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thinhhq.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thinhhq.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thinhhq.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thinhhq.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thinhhq.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thinhhq.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thinhhq.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thinhhq.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thinhhq.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thinhhq.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thinhhq.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thinhhq.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thinhhq.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thinhhq.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thinhhq.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thinhhq.wordpress.com&amp;blog=1429123&amp;post=12&amp;subd=thinhhq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thinhhq.wordpress.com/2008/09/06/upload-large-files-with-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e26618b4bd43dc127dd22d1a3c19e34d?s=96&#38;d=identicon" medium="image">
			<media:title type="html">thinhhq</media:title>
		</media:content>
	</item>
		<item>
		<title>Web Links</title>
		<link>http://thinhhq.wordpress.com/2007/10/12/web-links/</link>
		<comments>http://thinhhq.wordpress.com/2007/10/12/web-links/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 17:04:43 +0000</pubDate>
		<dc:creator>thinhhq</dc:creator>
				<category><![CDATA[Web Links]]></category>

		<guid isPermaLink="false">http://thinhhq.wordpress.com/2007/10/12/web-links/</guid>
		<description><![CDATA[http://port25.technet.com/default.aspx<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thinhhq.wordpress.com&amp;blog=1429123&amp;post=10&amp;subd=thinhhq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>http://port25.technet.com/default.aspx</p>
<p><a href="http://thinhhq.files.wordpress.com/2007/10/p25.gif" title="p25.gif"><img src="http://thinhhq.files.wordpress.com/2007/10/p25.gif?w=490" alt="p25.gif" /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thinhhq.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thinhhq.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thinhhq.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thinhhq.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thinhhq.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thinhhq.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thinhhq.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thinhhq.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thinhhq.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thinhhq.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thinhhq.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thinhhq.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thinhhq.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thinhhq.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thinhhq.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thinhhq.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thinhhq.wordpress.com&amp;blog=1429123&amp;post=10&amp;subd=thinhhq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thinhhq.wordpress.com/2007/10/12/web-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e26618b4bd43dc127dd22d1a3c19e34d?s=96&#38;d=identicon" medium="image">
			<media:title type="html">thinhhq</media:title>
		</media:content>

		<media:content url="http://thinhhq.files.wordpress.com/2007/10/p25.gif" medium="image">
			<media:title type="html">p25.gif</media:title>
		</media:content>
	</item>
		<item>
		<title>How to embed Windows Media Player in HTML document</title>
		<link>http://thinhhq.wordpress.com/2007/09/24/how-to-embed-windows-media-player-in-html-document/</link>
		<comments>http://thinhhq.wordpress.com/2007/09/24/how-to-embed-windows-media-player-in-html-document/#comments</comments>
		<pubDate>Mon, 24 Sep 2007 04:32:09 +0000</pubDate>
		<dc:creator>thinhhq</dc:creator>
				<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://thinhhq.wordpress.com/2007/09/24/how-to-embed-windows-media-player-in-html-document/</guid>
		<description><![CDATA[Windows Media Player Download &#160; Before to start, you should check the version of Windows Media Player installed on your computer. Version 6.4 is supported, but the latest version is recommended. Download If you need to install or update Windows Media Player, click on the logo to download the version of Windows Media Player compatible [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thinhhq.wordpress.com&amp;blog=1429123&amp;post=9&amp;subd=thinhhq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><strong>Windows Media Player Download</strong><img src="http://www.mioplanet.com/separator_right.gif" border="0" /></h2>
<table class="default" cellpadding="0" cellspacing="0" width="560">
<tr>
<td width="36">&nbsp;</td>
<td>Before to start, you should check the version of Windows Media Player installed on your computer. Version 6.4 is supported, but the latest version is recommended.</p>
<table class="default">
<tr>
<td class="vsmall" style="line-height:0;" align="center" width="100"><a href="http://www.microsoft.com/windows/windowsmedia/player/download/"> 				<img src="http://www.mioplanet.com/rsc/windows_media.jpg" alt="Windows Media Player" border="0" vspace="7" /><br />
Download</a></td>
<td>If you need to install or update Windows Media Player, click on the logo to download the version of Windows Media Player compatible with your operating system.</td>
</tr>
</table>
</td>
</tr>
</table>
<h2><strong>Embedding Windows Media Player</strong><img src="http://www.mioplanet.com/separator_right.gif" border="0" /></h2>
<table class="default" cellpadding="0" cellspacing="0" width="560">
<tr>
<td width="36">&nbsp;</td>
<td>To embed an object in HTML document, the object class ID is required. 	The class ID for Windows Media Player 7, 9, 10 and 11 is clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6.Insert the following code into your HTML document to embed Windows Media Player 7 and later:</td>
</tr>
</table>
<p>&lt;OBJECT id=&#8221;VIDEO&#8221; width=&#8221;320&#8243; height=&#8221;240&#8243;<br />
style=&#8221;position:absolute; left:0;top:0;&#8221;<br />
CLASSID=&#8221;CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6&#8243;<br />
type=&#8221;application/x-oleobject&#8221;&gt;</p>
<p>&lt;PARAM NAME=&#8221;URL&#8221; VALUE=&#8221;your file or url&#8221;&gt;<br />
&lt;PARAM NAME=&#8221;SendPlayStateChangeEvents&#8221; VALUE=&#8221;True&#8221;&gt;<br />
&lt;PARAM NAME=&#8221;AutoStart&#8221; VALUE=&#8221;True&#8221;&gt;<br />
&lt;PARAM name=&#8221;uiMode&#8221; value=&#8221;none&#8221;&gt;<br />
&lt;PARAM name=&#8221;PlayCount&#8221; value=&#8221;9999&#8243;&gt;<br />
&lt;/OBJECT&gt;</p>
<p>In the URL parameter, you can specify a URL (for streaming) or a local file.</p>
<p>If you are using a <a href="http://www.mioplanet.com/rsc/create_mio.htm"><u>Mio generator</u></a>, you should include the video file in your application.  	Including video reduce bandwidth usage and bring a better user experience.</p>
<p>Most important parameters supported by Windows Media Player 7 and later:</p>
<table class="default" bgcolor="#dddddd" border="0" cellpadding="5" cellspacing="1" width="100%">
<tr>
<th align="left" width="100">Parameter</th>
<th align="left" width="50">Default</th>
<th align="left">Description</th>
</tr>
</table>
<p><font color="#888888"> If you want to embed Windows Media Player 6.4 instead of the latest version, the class ID is clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95.</font></p>
<h2><strong>Controlling Windows Media Player from a JavaScript code</strong><img src="http://www.mioplanet.com/separator_right.gif" border="0" /></h2>
<table class="default" cellpadding="0" cellspacing="0" width="560">
<tr>
<td width="36">&nbsp;</td>
<td>You can control Windows Media Player from scripting.Start playback:</td>
</tr>
</table>
<p>VIDEO.URL=&#8221;filename&#8221;;</p>
<p>Stop playback:</p>
<p>VIDEO.controls.stop();</p>
<p>More methods:</p>
<p>VIDEO.controls.Pause();</p>
<p>Properties:</p>
<p>VIDEO.PlayState;<br />
VIDEO.controls.CurrentPosition;<br />
VIDEO.controls.Duration;</p>
<p>For more information:</p>
<p>http://msdn2.microsoft.com/en-us/library/ms983653.aspx</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thinhhq.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thinhhq.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thinhhq.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thinhhq.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thinhhq.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thinhhq.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thinhhq.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thinhhq.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thinhhq.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thinhhq.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thinhhq.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thinhhq.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thinhhq.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thinhhq.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thinhhq.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thinhhq.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thinhhq.wordpress.com&amp;blog=1429123&amp;post=9&amp;subd=thinhhq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thinhhq.wordpress.com/2007/09/24/how-to-embed-windows-media-player-in-html-document/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e26618b4bd43dc127dd22d1a3c19e34d?s=96&#38;d=identicon" medium="image">
			<media:title type="html">thinhhq</media:title>
		</media:content>

		<media:content url="http://www.mioplanet.com/separator_right.gif" medium="image" />

		<media:content url="http://www.mioplanet.com/rsc/windows_media.jpg" medium="image">
			<media:title type="html">Windows Media Player</media:title>
		</media:content>

		<media:content url="http://www.mioplanet.com/separator_right.gif" medium="image" />

		<media:content url="http://www.mioplanet.com/separator_right.gif" medium="image" />
	</item>
		<item>
		<title>PRB: Appdomains Security Permission Error Message When You Access the Strong-Named Assembly from the \Bin Directory</title>
		<link>http://thinhhq.wordpress.com/2007/08/03/8/</link>
		<comments>http://thinhhq.wordpress.com/2007/08/03/8/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 01:15:33 +0000</pubDate>
		<dc:creator>thinhhq</dc:creator>
				<category><![CDATA[.Net FW Setup & Configuration]]></category>

		<guid isPermaLink="false">http://thinhhq.wordpress.com/2007/08/03/8/</guid>
		<description><![CDATA[SYMPTOMS loadTOCNode(1, &#8216;symptoms&#8217;); In a Microsoft ASP.NET version 1.1 application, when you access a strong-named assembly that is stored in the \bin directory of your Web application that is not marked with AllowPartiallyTrustedCallersAttribute (APTCA) and when the trust level of the Web application is not set to Full Trust in the Web.config file, then you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thinhhq.wordpress.com&amp;blog=1429123&amp;post=8&amp;subd=thinhhq&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2 class="subTitle">SYMPTOMS</h2>
<p>loadTOCNode(1, &#8216;symptoms&#8217;);</p>
<p class="sbody">In a Microsoft ASP.NET version 1.1 application, when you access a strong-named assembly that is stored in the \bin directory of your Web application that is not marked with <strong>AllowPartiallyTrustedCallersAttribute</strong> (APTCA) and when the trust level of the Web application is not set to <strong>Full Trust</strong> in the Web.config file, then you may receive the following error message instead of the expected SecurityException error message:</p>
<p class="errormsg">Assembly <var>&lt;assembly&gt;</var>.dll security permission grant set is incompatible between appdomains</p>
<p>You will not receive the same error message in ASP.NET version 1.0, but the same underlying issue about strong-named assemblies also exists in ASP.NET 1.0. CAUSE</p>
<p>loadTOCNode(1, &#8217;cause&#8217;);</p>
<p class="sbody">Strong-named assemblies must be stored in the global assembly cache when they are used with ASP.NET Web applications. By default, strong-named assemblies will not grant access to partially trusted code, because of the visibility of strong-named assemblies in the global assembly cache. You can allow partially trusted code to call your strong-named assembly, but only after you explicitly set the <strong>AllowPartiallyTrustedCallersAttribute</strong>. If you do not explicitly declare the attribute, the caller requires <strong>Full Trust</strong> to use the code. Only apply the <strong>AllowPartiallyTrustedCallersAttribute</strong> to your strong-named assemblies after a careful assessment of the code.</p>
<p class="topOfPage">&nbsp;</p>
<h2 class="subTitle">RESOLUTION</h2>
<p>loadTOCNode(1, &#8216;resolution&#8217;);</p>
<p class="sbody">Install strong-named assemblies in the global assembly cache for ASP.NET 1.0 and 1.1 Web applications. The following steps describe how to install a strong-named assembly in the global assembly cache, and explain how to use the <strong>AllowPartiallyTrustedCallersAttribute</strong>:</p>
<p class="topOfPage">&nbsp;</p>
<h3>Install a Strong-Named Assembly in the Global Assembly Cache</h3>
<p>loadTOCNode(2, &#8216;resolution&#8217;);You can use the global assembly cache to share assemblies across many applications. To install the strong-named assembly in the global assembly cache, follow these steps:</p>
<table class="list ol">
<tr>
<td class="number">1.</td>
<td class="text">To create a strong-name assembly, follow the steps in the &#8220;More Information&#8221; section of this article.</td>
</tr>
<tr>
<td class="number">2.</td>
<td class="text">Open Visual Studio .NET Command Prompt, and then type the following command: <span class="userInput">gacutil -I &#8220;C:\[PathToBinDirectoryInVSProject]\<em>sampledll.dll</em></span><strong>Note</strong>: <em>sampledll.dll</em> is the name of the DLL that is signed with strong name.</td>
</tr>
</table>
<p class="topOfPage">&nbsp;</p>
<h3>Add the APTCA</h3>
<p>loadTOCNode(2, &#8216;resolution&#8217;);Assemblies that are intended to be called by partially trusted code declare their intent by the assembly-level custom attribute <strong>AllowPartiallyTrustedCallers</strong>. To mark the strong-named assembly with APTCA, follow these steps:</p>
<table class="list ol">
<tr>
<td class="number">1.</td>
<td class="text">To create a strong-name assembly, follow the steps in the &#8220;More Information&#8221; section of this article.</td>
</tr>
<tr>
<td class="number">2.</td>
<td class="text">Replace the code in Class1 with the following code:<strong>Visual C# .NET Code</strong><code></code><code></p>
<pre>using System; using System.Reflection; using System.Runtime.InteropServices; using System.Security;  [assembly: AssemblyKeyFile("..\..\key.snk")] [assembly:AllowPartiallyTrustedCallers]   namespace SNAssemblyTest { 	public class Class1 	{	// Test Class 	} }</pre>
<p><strong><font face="Times New Roman">Visual Basic .NET Code</font></strong><code></p>
<pre>Imports System.Reflection Imports System.Runtime.InteropServices Imports System.Security  &lt;Assembly: AssemblyKeyFile("....key.snk")&gt;  &lt;Assembly: AllowPartiallyTrustedCallers&gt;   Public Class Class1    ' Test Class End Class</pre>
<p></code></p>
<p></code></td>
</tr>
</table>
<p><strong>Note</strong> Only apply the <strong>AllowPartiallyTrustedCallersAttribute</strong> after you have considered the security implications and have taken the necessary precautions. These precautions include a code review against the secure coding guidelines that are described in the &#8220;Cause&#8221; section of this article. Only apply this attribute to assemblies if the following criteria are met:</p>
<table class="list ol">
<tr>
<td class="number">1.</td>
<td class="text">The assemblies have been designed and been built with explicit attention to security considerations to help protect them against all callers, including potentially malicious callers.</td>
</tr>
<tr>
<td class="number">2.</td>
<td class="text">Appropriate security testing with partially trusted code is completed before the code is released.</td>
</tr>
</table>
<p class="topOfPage">&nbsp;</p>
<h2 class="subTitle">STATUS</h2>
<p>loadTOCNode(1, &#8216;status&#8217;);</p>
<p class="sbody">This behavior is by design.</p>
<p class="topOfPage">&nbsp;</p>
<h2 class="subTitle">MORE INFORMATION</h2>
<p>loadTOCNode(1, &#8216;moreinformation&#8217;);</p>
<h3>Steps to Reproduce the Behavior</h3>
<p>loadTOCNode(2, &#8216;moreinformation&#8217;);</p>
<h4>Create a StrongName Assembly</h4>
<p>loadTOCNode(3, &#8216;moreinformation&#8217;);</p>
<table class="list ol">
<tr>
<td class="number">1.</td>
<td class="text">Start Microsoft Visual Studio .NET 2003.</td>
</tr>
<tr>
<td class="number">2.</td>
<td class="text">On the <strong>File</strong> menu, point to <strong>New</strong>, and then click <strong>Project</strong>.</td>
</tr>
<tr>
<td class="number">3.</td>
<td class="text">Select <strong>Visual C# project</strong> or <strong>Visual Basic Projects</strong> under <strong>Project Types</strong>.</td>
</tr>
<tr>
<td class="number">4.</td>
<td class="text">Select <strong>Class Library</strong> under <strong>Templates</strong>.</td>
</tr>
<tr>
<td class="number">5.</td>
<td class="text">Name the project as <span class="userInput">SNAssemblyTest</span>.</td>
</tr>
<tr>
<td class="number">6.</td>
<td class="text">Open the Visual Studio .NET Command Prompt, and then change the directory to the current project directory.</td>
</tr>
<tr>
<td class="number">7.</td>
<td class="text">To create a strong-named key, type the following command: <span class="userInput">sn -k key.snk</span></td>
</tr>
<tr>
<td class="number">8.</td>
<td class="text">Replace the code in Class1 with the following code:<strong>Visual C# .NET Code</strong><code></code><code></p>
<pre>using System; using System.Reflection; using System.Runtime.InteropServices;  [assembly: AssemblyKeyFile("..\..\key.snk")]  namespace SNAssemblyTest { 	public class Class1 	{	// Test Class 	} }</pre>
<p><strong><font face="Times New Roman">Visual Basic .NET Code</font></strong><code></p>
<pre>Imports System.Reflection Imports System.Runtime.InteropServices  &lt;Assembly: AssemblyKeyFile("....key.snk")&gt;   Public Class Class1    ' Test Class End Class</pre>
<p></code></p>
<p></code></td>
</tr>
<tr>
<td class="number">9.</td>
<td class="text">On the <strong>Build</strong> menu, click <strong>Build Solution</strong>.</td>
</tr>
</table>
<h4>Refer to the Assembly in an ASP.NET Web Application</h4>
<p>loadTOCNode(3, &#8216;moreinformation&#8217;);</p>
<table class="list ol">
<tr>
<td class="number">1.</td>
<td class="text">Start Visual Studio .NET, and then create a new ASP.NET Web Application project by using Visual C# .NET or Visual Basic .NET.</td>
</tr>
<tr>
<td class="number">2.</td>
<td class="text">In Solution Explorer, right-click <strong>References</strong>, and then click <strong>Add Reference</strong>.</td>
</tr>
<tr>
<td class="number">3.</td>
<td class="text">Click <strong>Browse</strong>, and then select the .dll file of the assembly that you created in the &#8220;Create a StrongName Assembly&#8221; section of this article (SNAssemblyTest.dll).</td>
</tr>
<tr>
<td class="number">4.</td>
<td class="text">To open the Web.config file, double-click <strong>Web.config</strong> in the Solution Explorer.</td>
</tr>
<tr>
<td class="number">5.</td>
<td class="text">Add the following code trust level code in the <strong>&lt;system.web&gt;</strong> element of the Web.config file:<code></p>
<pre>&lt;trust level="High"  /&gt;</pre>
<p></code></td>
</tr>
<tr>
<td class="number">6.</td>
<td class="text">To run the project, click <strong>Start</strong> on the <strong>Debug</strong> menu. You may receive the error that is mentioned in the &#8220;Symptoms&#8221; section of this article.</td>
</tr>
</table>
<h2 class="subTitle">REFERENCES</h2>
<p>loadTOCNode(1, &#8216;references&#8217;);</p>
<p class="sbody">For more information, visit the following Microsoft Web sites:</p>
<p class="indent">ASP.NET Code Access Security<br />
<a href="http://msdn2.microsoft.com/en-us/library/87x8e4d1.aspx">http://msdn2.microsoft.com/en-us/library/87x8e4d1.aspx</a><span class="pLink"> (http://msdn2.microsoft.com/en-us/library/87x8e4d1.aspx)</span><br />
MSDN Magazine “Security Briefs” (Hashing Passwords, The AllowPartiallyTrustedCallers Attribute)<br />
<span class="ll"><a href="http://msdn.microsoft.com/msdnmag/issues/03/08/SecurityBriefs/default.aspx">http://msdn.microsoft.com/msdnmag/issues/03/08/SecurityBriefs/default.aspx</a></span><span class="pLink"> (http://msdn.microsoft.com/msdnmag/issues/03/08/SecurityBriefs/default.aspx)</span><br />
Application Domains and Assemblies<br />
<a href="http://msdn2.microsoft.com/en-us/library/43wc4hhs(vs.71).aspx">http://msdn2.microsoft.com/en-us/library/43wc4hhs(vs.71).aspx</a><span class="pLink"> (http://msdn2.microsoft.com/en-us/library/43wc4hhs(vs.71).aspx)</span><br />
Strong Name Tool (Sn.exe)<br />
<a href="http://msdn2.microsoft.com/en-us/library/k5b5tt23(vs.71).aspx">http://msdn2.microsoft.com/en-us/library/k5b5tt23(vs.71).aspx</a><span class="pLink"> (http://msdn2.microsoft.com/en-us/library/k5b5tt23(vs.71).aspx)</span><br />
Version 1 Security Changes for the Microsoft .NET Framework<br />
<a href="http://msdn2.microsoft.com/en-us/library/ms994923.aspx">http://msdn2.microsoft.com/en-us/library/ms994923.aspx</a><span class="pLink"> (http://msdn2.microsoft.com/en-us/library/ms994923.aspx)</span><br />
Global Assembly Cache Tool (Gacutil.exe)<br />
<a href="http://msdn2.microsoft.com/en-us/library/ex0ss12c(vs.71).aspx">http://msdn2.microsoft.com/en-us/library/ex0ss12c(vs.71).aspx</a><span class="pLink"> (<a href="http://msdn2.microsoft.com/en-us/library/ex0ss12c(vs.71).aspx">http://msdn2.microsoft.com/en-us/library/ex0ss12c(vs.71).aspx</a>)</span></p>
<p class="indent"><span class="pLink"></span></p>
<p class="indent"><span class="pLink">Google: </span></p>
<p class="indent"><span class="pLink"></span></p>
<p class="indent"><span class="pLink"><a href="http://www.google.com.vn/search?hl=vi&amp;q=Assembly+security+permission+grant+set+is+incompatible+between+appdomains.+&amp;meta">http://www.google.com.vn/search?hl=vi&amp;q=Assembly+security+permission+grant+set+is+incompatible+between+appdomains.+&amp;meta</a>=</span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/thinhhq.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/thinhhq.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thinhhq.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thinhhq.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thinhhq.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thinhhq.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thinhhq.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thinhhq.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thinhhq.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thinhhq.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thinhhq.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thinhhq.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thinhhq.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thinhhq.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thinhhq.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thinhhq.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thinhhq.wordpress.com&amp;blog=1429123&amp;post=8&amp;subd=thinhhq&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thinhhq.wordpress.com/2007/08/03/8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e26618b4bd43dc127dd22d1a3c19e34d?s=96&#38;d=identicon" medium="image">
			<media:title type="html">thinhhq</media:title>
		</media:content>
	</item>
	</channel>
</rss>
