473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Progress bar implementation with flash + .Net. workin on local system.

Hi,

I have implement multiple file uploading progress bar with the help of flash and .net file is upload on my local machine but not working with server it's give error while uploading image on server. code is as follows.

this is flash object:
Expand|Select|Wrap|Line Numbers
  1.  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
  2.                 width="550" height="100" id="fileUpload" align="middle">
  3.                 <param name="allowScriptAccess" value="sameDomain" />
  4.                 <param name="movie" value="fileUpload.swf" />
  5.                 <param name="quality" value="high" />
  6.                 <param name="wmode" value="transparent">
  7.                 <param name="FlashVars" value='uploadPage=Upload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()'>
  8.                 <embed src="fileUpload.swf" flashvars='uploadPage=Upload.axd<%=GetFlashVars()%>&completeFunction=UploadComplete()'
  9.                     quality="high" wmode="transparent" width="550" height="100" name="fileUpload"
  10.                     align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash"
  11.                     pluginspage="http://www.macromedia.com/go/getflashplayer" />
  12.             </object>
  13.  
Code behind :
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         if (Request.Form != null)
  4.         {
  5.             //Upload obj = new Upload();
  6.             //obj.ProcessRequest( );
  7.             //Response.Write( Request.Form["__EVENTTARGET"].ToString());
  8.             //Response.Write( Request.Form["__EVENTARGUMENT"].ToString());
  9.         }
  10.  
  11.         Upload objImgfile = new Upload();
  12.         //Session["titleid"] = 354;
  13.         if (Upload.strmsg != "")
  14.         {
  15.             Response.Write(Upload.strmsg);
  16.             Upload.strmsg = "";
  17.         }
  18.  
  19.         // allows the javascript function to do a postback and call the onClick method
  20.         // associated with the linkButton LinkButton1.
  21.         string jscript = "function UploadComplete(){";
  22.         jscript += string.Format("__doPostBack('{0}','');", LinkButton1.ClientID.Replace("_", "$"));
  23.         jscript += "};";
  24.         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "FileCompleteUpload", jscript, true);
  25.     }
  26.  
  27.     protected string GetFlashVars()
  28.     {
  29.         // Adds query string info to the upload page
  30.         // you can also do something like:
  31.         // return "?" + Server.UrlEncode("CategoryID="+CategoryID);
  32.         // we UrlEncode it because of how LoadVars works with flash,
  33.         // we want a string to show up like this 'CategoryID=3&UserID=4' in
  34.         // the uploadPage variable in flash.  If we passed this string withou
  35.         // UrlEncode then flash would take UserID as a seperate LoadVar variable
  36.         // instead of passing it into the uploadPage variable.
  37.         // then in the httpHandler we get the CategoryID and UserID values from 
  38.         // the query string. See Upload.cs in App_Code
  39.         return "?" + Server.UrlEncode(Request.QueryString.ToString());
  40.     }
  41.  
and this code use one cs file to upload image which is as follows:
Expand|Select|Wrap|Line Numbers
  1. // According to http://msdn2.microsoft.com/en-us/library/system.web.httppostedfile.aspx
  2. // "Files are uploaded in MIME multipart/form-data format. 
  3. // By default, all requests, including form fields and uploaded files, 
  4. // larger than 256 KB are buffered to disk, rather than held in server memory."
  5. // So we can use an HttpHandler to handle uploaded files and not have to worry
  6. // about the server recycling the request do to low memory. 
  7. // don't forget to increase the MaxRequestLength in the web.config.
  8. // If you server is still giving errors, then something else is wrong.
  9. // I've uploaded a 1.3 gig file without any problems. One thing to note, 
  10. // when the SaveAs function is called, it takes time for the server to 
  11. // save the file. The larger the file, the longer it takes.
  12. // So if a progress bar is used in the upload, it may read 100%, but the upload won't
  13. // be complete until the file is saved.  So it may look like it is stalled, but it
  14. // is not.
  15.  
  16. using System;
  17. using System.Data;
  18. using System.Configuration;
  19. using System.Web;
  20. using System.Web.Security;
  21. using System.Web.UI;
  22. using System.Web.UI.WebControls;
  23. using System.Web.UI.WebControls.WebParts;
  24. using System.Web.UI.HtmlControls;
  25. using System.IO;
  26.  
  27. /// <summary>
  28. /// Upload handler for uploading files.
  29. /// </summary>
  30. public class Upload : IHttpHandler
  31. {
  32.     public static string strmsg;
  33.     public Upload()
  34.     {
  35.     }
  36.  
  37.     #region IHttpHandler Members
  38.  
  39.     public bool IsReusable
  40.     {
  41.         get { return true; }
  42.     }
  43.  
  44.     public void ProcessRequest(HttpContext context)
  45.     {
  46.         // Example of using a passed in value in the query string to set a categoryId
  47.         // Now you can do anything you need to witht the file.
  48.         //int categoryId = 0;
  49.         //if (context.Request.QueryString["CategoryID"] != null)
  50.         //{
  51.         //    try
  52.         //    {
  53.         //        categoryId = Convert.ToInt32(context.Request.QueryString["CategoryID"]);
  54.         //    }
  55.         //    catch (Exception err)
  56.         //    {
  57.         //        categoryId = 0;
  58.         //    }
  59.         //}
  60.         //if (categoryId > 0)
  61.         //{
  62.         //}
  63.  
  64.         if (context.Request.Files.Count > 0)
  65.         {
  66.             // get the applications path
  67.             string tempFile = context.Request.PhysicalApplicationPath;
  68.             // loop through all the uploaded files
  69.             for(int j = 0; j < context.Request.Files.Count; j++)
  70.             {
  71.                 // get the current file
  72.                 HttpPostedFile uploadFile = context.Request.Files[j];
  73.                 // if there was a file uploded
  74.                 if (uploadFile.ContentLength > 0)
  75.                 {
  76.                     // save the file to the upload directory
  77.  
  78.                     //use this if testing from a classic style upload, ie. 
  79.  
  80.                     // <form action="Upload.axd" method="post" enctype="multipart/form-data">
  81.                     //    <input type="file" name="fileUpload" />
  82.                     //    <input type="submit" value="Upload" />
  83.                     //</form>
  84.  
  85.                     // this is because flash sends just the filename, where the above 
  86.                     //will send the file path, ie. c:\My Pictures\test1.jpg
  87.                     //you can use Test.thm to test this page.
  88.                     //string filename = uploadFile.FileName.Substring(uploadFile.FileName.LastIndexOf("\\"));
  89.                     //uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "Upload\\", filename));
  90.  
  91.                     // use this if using flash to upload
  92.                     uploadFile.SaveAs(string.Format("{0}{1}{2}", tempFile, "Upload\\", uploadFile.FileName));
  93.                     HttpContext.Current.Response.Write(tempFile);
  94.                     strmsg = tempFile; 
  95.                     // HttpPostedFile has an InputStream also.  You can pass this to 
  96.                     // a function, or business logic. You can save it a database:
  97.  
  98.                     //byte[] fileData = new byte[uploadFile.ContentLength];
  99.                     //uploadFile.InputStream.Write(fileData, 0, fileData.Length);
  100.                     // save byte array into database.
  101.  
  102.                     // something I do is extract files from a zip file by passing
  103.                     // the inputStream to a function that uses SharpZipLib found here:
  104.                     // http://www.icsharpcode.net/OpenSource/SharpZipLib/
  105.                     // and then save the files to disk.                    
  106.                 }                
  107.             }
  108.         }
  109.         // Used as a fix for a bug in mac flash player that makes the 
  110.         // onComplete event not fire
  111.         HttpContext.Current.Response.Write(" ");
  112.     }
  113.  
  114.     #endregion
  115. }
Nov 14 '07 #1
0 3229

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: tmb | last post by:
1 - Can you build an entire web page or site with Java... sorta like you can with Flash? 2 - Can you do... .. Drag & Drop .. Push Buttons .. Hot Spot .. Hot Object .. Pull Down's (combo...
0
by: Joel Cade | last post by:
I'd just like a sanity check on my thinking. I'm attempting to create a progress bar for a file upload to an ASPX page. I'm adding an HTTP Module, which would then call into a "Progress Handler",...
16
by: Jordan Abel | last post by:
I have written this function and was wondering if anyone else could point out if there's anything wrong with it. The purpose is to substitute for printf when in a situation where low-level I/O has...
9
by: Scirious | last post by:
People, I want to do same things with a progress bar but I don't know how. So, how do I change it to make it a solid bar, not a step byt step as the default? And how do I make it a vertical bar?...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
11
by: processoriented | last post by:
Hi, I'm something of a noob at this, but here it is... I have an app that fills a dataset from a SQL database, and then writes the dataset to an xml file. Everything is a SELECT query... I am...
1
by: spirit | last post by:
Hi all, I have created a flash object and a javascript menu. It works properly in IE, but in Mozilla the mane gets hides behind the flash object. Due to this i m not able to view the menu. Can any...
1
by: redet | last post by:
A demo created by a person who has since left, runs fine on a local (Windows XP) system within flash player 8, but when we try to access it through the html version (index.html) on a local system or...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.