| | |
Custom HttpHandler.
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 13
Reputation:
Solved Threads: 0
I am developing a multi file uploader user control.
after researching for it. the trick is to build a custom HttpHandler to perform the upload process from the context.request.files.
here is the code for my handler:
namespace PSUpload
{
///<summary>
/// Custom HttpHandler to perform uploading files from client
/// to server.
///</summary>
public class PSUploader : IHttpHandler
{
#region Member Variables
private string dirPath = string.Empty;
private DirectoryInfo dir = null;
private string baseLocation = string.Empty;
#endregion
#region Constructor
///<summary>
/// constructor, assing the dirPath string to the AttachPath
/// which is set in the web.config.
/// instantiate the dir DirectoryInfo to check if the directory exist
/// or not.
/// assing the baselocation string to the DirectoryInfo dir.
///</summary>
public PSUploader()
{
dirPath = ConfigurationSettings.AppSettings"AttachPath"].ToString();
dir = new DirectoryInfo(dirPath);
//create the directory if it does not exist.
if (!dir.Exists)
{
dir.Create();
}
baseLocation = dir.ToString();
}
#endregion
#region ProcessRequest
///<summary>
/// called when a page is requested.
/// foreach posted file in the context. save the file to server(upload it).
///</summary>
///<param name="context"></param>
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
for (int indx = 0 ; indx < context.Request.Files.Count ; indx++)
{
HttpPostedFile file = context.Request.Files[indx];
if (file.ContentLength > 0)
{
file.SaveAs(baseLocation + file.FileName);
}
}
}
}
#endregion
#region IsReusable
public bool IsReusable
{
get
{
return true;
}
}
#endregion
}
}
after that i have registered my handler in the web.config file using the following line:
<httpHandlers>
<addverb="*"path="*.aspx"type="PSUpload.PSUploader,PSUpload"/>
</httpHandlers>
the problem is when i run the application, i just get an empty page without the user control or anything. when i view source code from the browser. i just get the following:
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1256"></HEAD>
<BODY></BODY></HTML>
i dont know what the problem is.
does anyone has a clue of what the problem seems to be? is there anything missing in my code?
please help
thanx.
after researching for it. the trick is to build a custom HttpHandler to perform the upload process from the context.request.files.
here is the code for my handler:
namespace PSUpload
{
///<summary>
/// Custom HttpHandler to perform uploading files from client
/// to server.
///</summary>
public class PSUploader : IHttpHandler
{
#region Member Variables
private string dirPath = string.Empty;
private DirectoryInfo dir = null;
private string baseLocation = string.Empty;
#endregion
#region Constructor
///<summary>
/// constructor, assing the dirPath string to the AttachPath
/// which is set in the web.config.
/// instantiate the dir DirectoryInfo to check if the directory exist
/// or not.
/// assing the baselocation string to the DirectoryInfo dir.
///</summary>
public PSUploader()
{
dirPath = ConfigurationSettings.AppSettings"AttachPath"].ToString();
dir = new DirectoryInfo(dirPath);
//create the directory if it does not exist.
if (!dir.Exists)
{
dir.Create();
}
baseLocation = dir.ToString();
}
#endregion
#region ProcessRequest
///<summary>
/// called when a page is requested.
/// foreach posted file in the context. save the file to server(upload it).
///</summary>
///<param name="context"></param>
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
for (int indx = 0 ; indx < context.Request.Files.Count ; indx++)
{
HttpPostedFile file = context.Request.Files[indx];
if (file.ContentLength > 0)
{
file.SaveAs(baseLocation + file.FileName);
}
}
}
}
#endregion
#region IsReusable
public bool IsReusable
{
get
{
return true;
}
}
#endregion
}
}
after that i have registered my handler in the web.config file using the following line:
<httpHandlers>
<addverb="*"path="*.aspx"type="PSUpload.PSUploader,PSUpload"/>
</httpHandlers>
the problem is when i run the application, i just get an empty page without the user control or anything. when i view source code from the browser. i just get the following:
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1256"></HEAD>
<BODY></BODY></HTML>
i dont know what the problem is.
does anyone has a clue of what the problem seems to be? is there anything missing in my code?
please help
thanx.
•
•
•
•
I am developing a multi file uploader user control.
after researching for it. the trick is to build a custom HttpHandler to perform the upload process from the context.request.files.
here is the code for my handler:
namespace PSUpload
{
///<summary>
/// Custom HttpHandler to perform uploading files from client
/// to server.
///</summary>
public class PSUploader : IHttpHandler
{
#region Member Variables
private string dirPath = string.Empty;
private DirectoryInfo dir = null;
private string baseLocation = string.Empty;
#endregion
#region Constructor
///<summary>
/// constructor, assing the dirPath string to the AttachPath
/// which is set in the web.config.
/// instantiate the dir DirectoryInfo to check if the directory exist
/// or not.
/// assing the baselocation string to the DirectoryInfo dir.
///</summary>
public PSUploader()
{
dirPath = ConfigurationSettings.AppSettings"AttachPath"].ToString();
dir = new DirectoryInfo(dirPath);
//create the directory if it does not exist.
if (!dir.Exists)
{
dir.Create();
}
baseLocation = dir.ToString();
}
#endregion
#region ProcessRequest
///<summary>
/// called when a page is requested.
/// foreach posted file in the context. save the file to server(upload it).
///</summary>
///<param name="context"></param>
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
for (int indx = 0 ; indx < context.Request.Files.Count ; indx++)
{
HttpPostedFile file = context.Request.Files[indx];
if (file.ContentLength > 0)
{
file.SaveAs(baseLocation + file.FileName);
}
}
}
}
#endregion
#region IsReusable
public bool IsReusable
{
get
{
return true;
}
}
#endregion
}
}
after that i have registered my handler in the web.config file using the following line:
<httpHandlers>
<addverb="*"path="*.aspx"type="PSUpload.PSUploader,PSUpload"/>
</httpHandlers>
the problem is when i run the application, i just get an empty page without the user control or anything. when i view source code from the browser. i just get the following:
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1256"></HEAD>
<BODY></BODY></HTML>
i dont know what the problem is.
does anyone has a clue of what the problem seems to be? is there anything missing in my code?
please help
thanx.
This is what asp.net pages display when there is no output. And for this hander you are not displaying anything on the page.
If you want to put something on the page either do a Response.Write("") or use a regular aspx page with controls.
![]() |
Similar Threads
- custom .htaccess file 301 Redirect to non www form (Search Engine Optimization)
- Internet Explorer Favorites, custom website icons disappearing (Web Browsers)
- Looking for a cheap custom vbulletin style (Web Development Job Offers)
- Security Settings -> Java permission -> Custom (radio button) -> Java Custom Settings (Web Browsers)
- Internet Security Keeps Resetting To Custom (HiJackThis Log) (Viruses, Spyware and other Nasties)
Other Threads in the ASP.NET Forum
- Previous Thread: check date
- Next Thread: does C# Window Service supports Browser_DocumentCompleted event of Web browser?
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox class compatible confirmationcodegeneration content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv forms gridview gudi homeedition iis javascript jquery list listbox menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xml xsl





