?
Solved

Upload progress bar

Posted on 2013-06-17
7
Medium Priority
?
553 Views
Last Modified: 2013-06-30
Hi,

Can replace an .ashx file with c# class file? The following script shows file upload progress bar by linking to an .ashx file. I want to upload file by browsing the file only without clicking any button to upload. Please help me to modify the code or give me any sample if any.

aspx page:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="AutoUpload.aspx.cs" Inherits="_Default" %>

<!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></title>
     <link rel="Stylesheet" type="text/css" href="CSS/uploadify.css" />
     <script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.uploadify.js"></script>
</head>
<body>
<form id="form1" runat="server">
    <div style = "padding:40px">
        <asp:FileUpload ID="FuSTL" runat="server" />
    </div>
</form>
</body>
</html>
<script type = "text/javascript">
$(window).load(
    function() {
       $("#<%=FuSTL.ClientID %>").fileUpload({
        'uploader': 'scripts/uploader.swf',
        'cancelImg': 'images/cancel.png',
        'buttonText': 'Browse Files',
        'script': 'Upload.ashx',
        'folder': 'uploads',
        'fileDesc': 'STL Files',
        'fileExt': '*.stl',
        'multi': true,
        'auto': true
    });
   }
);
</script> 

Open in new window


.ashx file:
<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.Web;
using System.IO;

public class Upload : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;
        try
        {
            HttpPostedFile postedFile = context.Request.Files["Filedata"];
            
            string savepath = "";
            string tempPath = "";
            tempPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; 
            savepath = context.Server.MapPath(tempPath);
            string filename = postedFile.FileName;
            if (!Directory.Exists(savepath))
                Directory.CreateDirectory(savepath);

            postedFile.SaveAs(savepath + @"\" + filename);
            context.Response.Write(tempPath + "/" + filename);
            context.Response.StatusCode = 200;
        }
        catch (Exception ex)
        {
            context.Response.Write("Error: " + ex.Message);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}

Open in new window



Thanks

ayha
0
Comment
Question by:ayha1999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 82

Expert Comment

by:David Johnson, CD, MVP
ID: 39254351
How will your calling program know that you've completed browsing to the file and selected the right one?  It does need the user to indicate to the calling program that they have selected the correct file. This is especially the case in a web project, in which the user has control and not the caller.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 39260391
Can I replace .ahsx file with classs file?  The code for writing the file to a folder is in .ahsx file. I want to do it in a button click event of aspx page. the javascript is referring to .ahsx file name. Can I still refer to .ahsx if I compile the project?

ayha
0
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 39265073
You cannot upload files without using an upload button. Users have to choose to upload files to your server. This is a security issue and no browser will allow you to do that.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Author Comment

by:ayha1999
ID: 39265081
I have to use upload button. Can I replace .ashx file with class file? I want write the code to upload file to folder and db in an aspx file instead of .ashx file.

Thanks
0
 
LVL 27

Accepted Solution

by:
Sammy Ageil earned 1000 total points
ID: 39266488
Of course you can, its just a server control with its own events.
here is an example on Microsoft site with a step by step
http://support.microsoft.com/kb/323246
0
 
LVL 7

Author Comment

by:ayha1999
ID: 39266526
What I am trying here, to replace .ashx file with class file. the .ashx file referred in the    'script': 'Upload.ashx'," I want to remove it do all the upload operations in aspx code behind file.

Thanks
0
 
LVL 27

Expert Comment

by:Sammy Ageil
ID: 39269947
Do you actually want someone to do this for you and provide you with the code?
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question