asp.net upload multiple files

by Hassan 1. June 2010 02:45

 

This free tool helps you to upload multiple files at once, it's common problem to find difficulty uploading multiple files unless you add more controls to the page, which cause a mass in your design.

 

 

This simple tool helps you to pload as many files as you want, just write the number of files in "FileNumber" property in properties window, you'll be allowed to upload the number you apply to this property.

 

This control contains number of HtmlInputFile control, all are hidden except the one you're using, this simple idea keeps your page design simple, it looks one control, but it contains as many as you want HtmlInputFile control.

 

Try the control with the following code, this code makes sure that all the files are in JPEG or GIF format, below 18kb size and upload the files in Files folder, try the code with the control.

Download the file FilesUploader.zip (8.52 kb)

Find the Demo page

 

  

 

 

 

Protected void FilesUploader1_UploadClick(object sender, EventArgs e)
{
if (Request.Files.Count > 0)
{
StringBuilder bd = new StringBuilder();
string ext = null;
for (int i = 0; i < Request.Files.Count ; i++)
{
int fileNamePos = Request.Files[i].FileName.LastIndexOf("\\") + 1;
string fileName = Request.Files[i].FileName.Substring(fileNamePos);
ext = fileName.Substring(fileName.Length - 3);
if ((ext.ToLower() == "jpg") || (ext.ToLower() == "gif"))
{
if(Request.Files[i].ContentLength < 18000)
{
Request.Files[i].SaveAs(Server.MapPath(
"~/files/"+ fileName));
bd.Append(
"files/" + fileName + "<br>");
this.Label2.Text = bd.ToString();
this.Label2.Visible = true;}
else
{
this.errorLbl.Text = "The file " + fileName + " is too big";
this.errorLbl.Visible = true;
}
}
else
{
this.errorLbl.Text = "Only image format allowed";
this.errorLbl.Visible = true;

protected

Free html editor asp.net - FCKeditor

by Hassan 24. May 2010 04:56

FCKeditor is a very powerful wysiwyg editor for asp.net, it has alot of good feautres that rarely to be available in free tool, it's important to follow the installation steps to make it available, a lot of people got stuck in installation process and forget about it.

 

 

Let's first talk about the tool features before talking about the installation steps.
* Basic and Advanced Styling          * Real Block-quoting         * Advanced Paste from Word
* Advanced Linking                        * E-mail Linking               * Visual Link Anchors
* Right to Left Interface                 * Find and Replace           * Flash Content
* Easy Tables                               * Print Breaks                  * Smiles
* Form Creation Tools                    * Spell Check as You Type * Intuitive Context Menu
* Strong Accessibility                     * Keyboard Navigable       

 

To install the tool, you have to download two versions, both are available in the download page, download both the FCKeditor and FCKeditor for dotnet.

 

The collapsible toolbar is customizable, you can switch between default and basic toolbar view. If you want to use the RequiredFieldValidator control you have to set "EnableclientScript" to false. 

 

differences between response.redirect vs server.transfer

by abu3aly 22. May 2010 21:37

Both funtions are giving the same result, which is the site visitor will be redirected to another webpage, but there are small differences betweeb both that will make you choose one of them based on your suitation.

 

Response.Redirect function redirects the user to another page, the changed easly noticed by the url changing, it'll tell you exactly where you are, and you can bookmark the page you're in. 

 

Server.Transfare is a moving process inside the same domain, site visitor will not feel the transfaring process, the URL will not be changed, Server.Transfare dosn't disply the true URL, so the user could be misslead if he try to Bookmark or email the page to a friend.

 

If you try to use Server.Transfare to redirect to a page outside your domain, you'll got the followign error msg
Invalid path for child request 'http://www.anotherdomain.com'. A virtual path is expected.

 

The example below showing how can you use Context.Handler to transfare data between pages in Server.Transfare function.

 

Assume that you have two pages: FirstPage.aspx and SecondPage.aspx
In FirstPage.aspx.cs write the following code:

 

void Page_Load(object sender, EventArgs e)
{
Server.Transfer(
"secondpage.aspx"
);
}  
 
internal Hashtable Value
{
get

{
Hashtable obj = new Hashtable
();
obj["Name"] = "My Name"
;
obj[
"Second"] = "My Second Name"
;
obj[
"Address"] = "Shoubra"
;
return
obj;
}
}
 

 

In the ScondPage.aspx.cs write the following code

 

 protected void Page_Load(object sender, EventArgs e)
{
Hashtable obj = new Hashtable
();
if
(!IsPostBack)
{
FirstPage ParentPage;
ParentPage = (FirestPage)Context.Handler;
obj = ParentPage.Value;
Response.Write(
"<br><br>"
);
foreach (DictionaryEntry di in
obj)
{
Response.Write(di.Key +
" : "
+ di.Value);
Response.Write(
"<br>"
);
}
}

Add new rules to regularexpressionvalidator control

by abu3aly 20. May 2010 19:00

Regularexpressionvalidator tool is asp.net important validation tool, using this tool give you the power to make a special validation rule to move to the next page. This tool comes with a built in rules that could be used, if you want to use a special regular expression, click validationExpression field in the properties menu.

 

Save More Expression

In case that you're using spacific regular expressions regullary, you don't have to add it to the tool every time you want to use, simply add more regular expressions and just invoke the one you want from a dropdown menu like the picture in the right.

 

Add more Expressions

In this article the auther inhrit the tool, and make the ability to add your expressions to be available in dorpdownlist, like you can see in the picture above, there is a new filed added to the properties menu called "CustomExpressions" this tool include more expressions that you can add, just collect the expressions you're using and make the ncessary modifications to accept more expressions.

 

On the web

This link includes the article page, with the ability to download a dll file after making the modifications, copy the code and change the expressions with yours to get more powerful and customizable regularexpression tool.