blogspot visit counter

Friday 19 April 2013

Ajax AsyncFileUpload control example in asp.net to upload files to server

Ajax AsyncFileUpload control example in asp.net to upload files to server


Introduction:


Here I will explain how to use Ajax AsyncFileUpload control to upload files to folder and show progress bar during upload files to server using asp.net.If you want to upload file on the web server then you do not define the path it use virtual path of our folder only set the read and write permission on the folder.

Description : -

I will explain how to use ajax AsyncFileUpload control to upload files to folder in asp.net. Before proceed to implement sample have you install ajaxcontroltoolkit in visual studio or not if not install it otherwise if you already done then follow the below steps to implement Ajax AsyncFileUpload control example in asp.net.

First create one new website after that right click on it add new folder and give name as ‘Files’ after that add AjaxControlToolkitreference to your application and add following line in your aspx page
<%@ Register Namespace="AjaxControlToolkit"Assembly="AjaxControlToolkit"tagPrefix="ajax"%>
Once add above references design your aspx page will be likes this
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
// This function will execute after file uploaded successfully
function uploadComplete() {
document.getElementById('<%=lblMsg.ClientID %>').innerHTML = "File Uploaded Successfully";
}
// This function will execute if file upload fails
function uploadError() {
document.getElementById('<%=lblMsg.ClientID %>').innerHTML = "File upload Failed.";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="scriptManager1" runat="server"/>
<div>
<ajax:AsyncFileUpload ID="fileUpload1" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError"
CompleteBackColor="White" Width="350px" runat="server" UploaderStyle="Modern" UploadingBackColor="#CCFFFF"
ThrobberID="imgLoad" OnUploadedComplete="fileUploadComplete" /><br />
<asp:Image ID="imgLoad" runat="server" ImageUrl="loading.gif" />
<br />
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>


If you observe above code I define lot of properties to ajax:AsyncFileUpload now I will explain all the

Now in code behind add following namespaces

C# Code 


using System;
using System.Web.UI;
using AjaxControlToolkit;

After completion of adding namespaces write following code in code behind
protected void fileUploadComplete(object sender, AsyncFileUploadEventArgs e)
{
string filename = System.IO.Path.GetFileName(fileUpload1.FileName);
fileUpload1.SaveAs(Server.MapPath("Files/") + filename);
}

VB Code

Imports System.Web.UI
Imports AjaxControlToolkit
Partial Class Default
Inherits System.Web.UI.Page
Protected Sub fileUploadComplete(ByVal sender As Object, ByVal e As AsyncFileUploadEventArgs)
Dim filename As String = System.IO.Path.GetFileName(fileUpload1.FileName)
fileUpload1.SaveAs(Server.MapPath("Files/") & filename)
End Sub
End Class

Download sample code attached







How Install Ajax in visual studio?

    1) First step is to download the latest version of the Ajax Control Toolkit from CodePlex whichever suits to your visual studio. If you are using Visual Studio 2008 then you should pick the version of the Ajax Control Toolkit for .NET 3.5. If you are using Visual Studio 2010 then you can use either the .NET 4 or .NET 3.5 versions of the Ajax Control Toolkit.


12 comments:

  1. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.
    redmi note service center in chennai
    redmi service center in velachery
    redmi service center in t nagar
    redmi service center in vadapalani

    ReplyDelete
  2. Thanks for sharing content and such nice information for me. I hope you will share some more content about. Please keep sharing!
    Artificial Intelligence Training In Hyderabad

    ReplyDelete
  3. Great writing! You have a flair for informational writing. Your content has impressed me beyond words.Thank you for all your valuable input on this topic.
    SAP training in Kolkata
    Best SAP training in Kolkata
    SAP training institute in Kolkata

    ReplyDelete
  4. Thanks a lot very much for the high your blog post quality and results-oriented help. I won’t think twice to endorse to anybody who wants and needs support about this area.

    java training in chennai

    java training in velachery

    aws training in chennai

    aws training in velachery

    python training in chennai

    python training in velachery

    selenium training in chennai

    selenium training in velachery

    ReplyDelete
  5. A great piece of writing! You have an efficient flair for high quality writing. I am highly impressed by your way of writing this content beyond words. I really have a lot of appreciation for your writing. Thank you so much for all your priceless input on this topic.
    SAP training in Kolkata
    SAP course in kolkata
    SAP training institute in Kolkata

    ReplyDelete
  6. Thanks for posting the best information and the blog is very important
    data science interview questions and answers

    ReplyDelete
  7. Very nice blog. A great piece of writing. You have shared a true worthy blog and keep sharing more blogs with us. Thank you.
    Data Science Certification in Hyderabad

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...