Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi All,

 

Does anyone know if or how it is posible to show or an image or a progressbar while uploading a lage file.

 

I've seached the forum/i-net but didn't find anything usefull :o

I'm using VS2005 and tried to hide/unhide an image but with no success.

 

Thanks!

Posted (edited)
EDIT- I feel really supid, completely misread your post. Thought you were downloading, not uploading. How are you uploading, via the upload control? Edited by Nate Bross

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

Allright here we go

 

  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       Dim UploadPath As String = ConfigurationSettings.AppSettings.Get("UploadPath")
    
'-- This is the loading image
     ImgLoading.Visible = False

'-- The upload button generates a postback 

       If IsPostBack Then
'-- Show the loading image 
           ImgLoading.Visible = True

           Dim path As String = Server.MapPath("~/" + UploadPath + "/")
           Dim fileOK As Boolean = False
           If FileUpload1.HasFile Then
               Dim fileExtension As String
               fileExtension = System.IO.Path. _
                   GetExtension(FileUpload1.FileName).ToLower()
               Dim allowedExtensions As String() = _
                   {".jpg", ".jpeg", ".xls", ".pps", ".doc"}
               For i As Integer = 0 To allowedExtensions.Length - 1
                   If fileExtension = allowedExtensions(i) Then
                       fileOK = True
                   End If
               Next
               If fileOK Then
                   Try
                       FileUpload1.PostedFile.SaveAs(path & _
                            FileUpload1.FileName+ fileExtension)
                       Label1.Text = "File uploaded"
                   Catch ex As Exception
                       Label1.Text = "File can't be uploaded"
                   End Try
               Else
                   Label1.Text = "File extention is not allowed"
               End If
           End If
'-- and hide the loading image again
           ImgLoading.Visible = False
       End If
   End Sub

 

Weel that's it realy :)

Posted

I haven't used the Upload control yet, but from your code, I don't think a real progressbar is possible, because the line of code

 

FileUpload1.PostedFile.SaveAs(path & _
                            FileUpload1.FileName+ fileExtension)

 

is actually executing a function along the lines of this

 

Function SaveAs(ByVal sPath as String) 
   While I have bytes to upload
       Upload those bytes 
       Save them to the givin sPath
   Loop
End Function

 

because this is the case, you cannot add a value to the progressbar's value every time through the loop.

 

Same concept as the Winsock control in legacy Visual Basic, if you give the senddata function all of the data at once, it loops behind the scenes which doesn't allow you to use a progresssbar in an effective mannor.

 

In short, I don't know of a way to use a progressbar while uploading large files. What I would do is make an animated gif similar to the Windows XP "Copy File Dialog" and display that.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

Yup, that's what I tried.. but... when I click the upoload button, the animated gif freezes... :S until the file is totaly uploaded.. ( so that's NOT what i want)

 

furthermore ... the hole page freezes.. I even can't enable/ disable the buttons. ( to prevent the user clicking 12 times in a row while the file is loading)

 

... stange huh?

 

Any idear hoe this is posible??

Posted
I really don't have any idea, maybe as a work around you could put the upload control on a frame, and also make sure that all the rest of your disable code is before the call to the upload control's SaveAs method.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

I found a sort off work around... ( ****ty but hey... that MS right? ;) )

 

What I did is

 

Create all Panels, buttons, and images on the page ( if you set the visible on false the objact cant be fetched by javascript...)

 

In the onload event of the aspx page I call a Javascript function

 

<body onLoad="HideLabels()">

 

This function


function HideLabels()
{
document.getElementById('LblLoading').style.visibility = "Hidden";
document.getElementById('imgLoading').style.visibility = "Hidden";
}

 

This will hide the "Please wait while file is being uploaded" label and its STATIC image ( sinds animated images 'hang' when you upload a file)

 

When the user clicks Upload first a Javascript functions is called to hide and show some labels.

<asp:Button ID="BtnUpload" runat="server" Style="left: 10px; position: relative; top: 22px" Text="Upload" OnClientClick="ShowThoseThings" />

 

function ShowThoseThings()
{


document.getElementById('PnlUpload').style.visibility = "Hidden";
document.getElementById('LblLoading').style.visibility = "Visible";
document.getElementById('imgLoading').style.visibility = "Visible";
}

 

Op the Page.load in the VB code the upload process starts.. en when finished sets another label :)

 

Thanks for your time! Hope it helps

 

Cheers Mrb

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...