Category Archives: FileUpload

[RESOLVED] how to post a video on video player

I want to post few videos on a website but i don't want to use youtube or any other website.

I want to have an in-build player on the webpage with video in it - how to accoplish that ?

Object tag????

if you dont prefer got to think of Silverlight...


How I can do this :

Could you please help me with the code and things needs to be done in order to accoplish this ?

Complete code....

<%@ Page Language="C#"%>
<%@ Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
        String UpPath;
        UpPath = "C:\\UploadedUserFiles";

        if (!Directory.Exists(UpPath))
    protected void btnSubmit_Click(object sender, EventArgs e)
        HttpFileCollection uploads = HttpContext.Current.Request.Files;
        for (int i = 0; i < uploads.Count; i++)
            HttpPostedFile upload = uploads[i];

            if (upload.ContentLength == 0)

            string c = System.IO.Path.GetFileName(upload.FileName); // We don't need the path, just the name.

                upload.SaveAs("C:\\UploadedUserFiles\\" + c);
                Span1.InnerHtml = "Upload(s) Successful.";
            catch (Exception Exp)
                Span1.InnerHtml = "Upload(s) FAILED.";

<html xmlns="">
<head id="Head1" runat="server">
<form id="form1" runat="server" enctype="multipart/form-data">
<p id="upload-area">
   <input id="File1" type="file" runat="server" size="60" />

<input id="AddFile" type="button" value="Add file" onclick="addFileUploadBox()" />
<p><asp:Button ID="btnSubmit" runat="server" Text="Upload Now" OnClick="btnSubmit_Click" /></p>
<span id="Span1" runat="server" />

<script type="text/javascript">
    function addFileUploadBox() {
        if (!document.getElementById || !document.createElement)
            return false;

        var uploadArea = document.getElementById("upload-area");

        if (!uploadArea)

        var newLine = document.createElement("br");

        var newUploadBox = document.createElement("input");

        // Set up the new input for file uploads
        newUploadBox.type = "file";
        newUploadBox.size = "60";

        // The new box needs a name and an ID
        if (!addFileUploadBox.lastAssignedId)
            addFileUploadBox.lastAssignedId = 100;

        newUploadBox.setAttribute("id", "dynamic" + addFileUploadBox.lastAssignedId);
        newUploadBox.setAttribute("name", "dynamic:" + addFileUploadBox.lastAssignedId);

[RESOLVED] Do TabPanels in a TabContainer have click events etc


I have a TabContainer with 2 TabPanels. In TabPanel1 I have a AsyncFileUpload control.

This AsyncFileUpload must be Visible="false" as I have ActiveTabIndex="1" in the TabContainer. If not, there will be a compile error when trying to access the Page.

Now when I click the Tab of TabPanel1, this AsyncFileUpload controls needs to be Visible="true".


I am not sure how I can achieve this. Has TabPanels some kind of click event etc?

<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1"
                        CssClass="fancy" Font-Names="Arial" Width="787px">
<cc1:TabPanel runat="server" ID="TabPanel1" Height="100%" HeaderText="TabPanel1" >
<cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server"
                        FailedValidation="False" OnClientUploadComplete="UploadComplete"
                        OnClientUploadError="uploadError" OnClientUploadStarted="StartUpload"
                        UploadingBackColor="#66CCFF" Visible="False" Width="320px" />

<cc1:TabPanel runat="server" ID="TabPanel2" Height="100%" HeaderText="TabPanel2" >


Try this one <cc1:TabContainer onactivetabchanged="tabProductInfo_ActiveTabChanged" ID="tabProductInfo" runat="server" ActiveTabIndex="0" Width="100%" ScrollBars="Auto" >

Thank you, it seems interesting. I have to ask a bit more.

This should be a C# event as I understand: onactivetabchanged="tabProductInfo_ActiveTabChanged"


If it is, how would that event look like to know I am setting it up correctly?

Thank you! 


I am not sure but I beleive there must be a C# event for this onactivetabchanged but are not sure how to set that event handler up in C#?

<cc1:TabContainer onactivetabchanged="tabProductInfo_ActiveTabChanged" ID="tabProductInfo" runat="server" ActiveTabIndex="0" Width="100%" ScrollBars="Auto" >


You can just add this event to your code behind,  

        protected void tabProductInfo_ActiveTabChanged( object sender, EventArgs e )

If you are lazy like me, get the tab control in your properties explorer in the designer, then  click the little lightening bolt icon at the top of the properties explorer.
This will then display all the server events for the control.  Next just double click the empty input box next to the event you need, in your case ActiveTabChanged.  
VS should then create and name the event for you and show display it in the codebehind page.  This is very handy for any server control event you want to create.

Thank you, then I understand how you ment.

I think I have set it up as it should be then.

It seems to work out fine.


Thank you!

<cc1:TabContainer id="tabconLandTransPlan" runat="server" Width="806" onactivetabchanged="tabProductInfo_ActiveTabChanged" AutoPostBack="True"
                  ActiveTabIndex="4" CssClass="fancy" Font-Names="Arial" >

    protected void tabProductInfo_ActiveTabChanged(object sender, EventArgs e)
        if (tabconLandTransPlan.ActiveTabIndex == 1)
            AsyncFileUpload1.Visible = true;
            AsyncFileUpload2.Visible = true;
            AsyncFileUpload1.Visible = false;
            AsyncFileUpload2.Visible = false;


[RESOLVED] open Dialog Box

 Hi All,

how can I  show open dialog box in but without using fileupload control,cause I just want to select

the url and assign it to imageurl property of image control to show image before save to database



To my knowledge there is no way to do that without FileUpload in

the options which you are left with is to use ActivX or Silverlight for this kind of requirement....



You can see here

An Open File Dialog in JavaScript



[RESOLVED] Dispaly image of fileupload control

hi all,

please if could anyone help me in how can I dispaly image on image control after user choose it using fileupload control




Here is Code and Explaination

Dispaly image of fileupload control



There is no proper way of doing this on client side....many browsers have restrictions on this.....and especially without uploading the is not possible to generate clientside is possible in IE, but not FF....

So what I would suggest is to submit the form asynchronously to server, and then generate the preview....finally when user selects upload, then actually upload the image....

what i mean was....user selects the image...send the image to the server, but dont save it....then display image in the image control using Bitmap....then when user selects upload, then save the image on the server....


[RESOLVED] FileUpload control don't work on first submission


I'm having a problem with the FileUpload control in ASP.NET. It requires two postbacks to server in order to upload the file. In other words, after I select the file and click upload the page reloads but do nothing. Then I reselect the file and click upload then it works.

In my code I put a check for FileUpload.HasFile and it always fails (return false) on the first postback. 

Does anybody have any information regarding this problem?



Are you using fileupload inside update panel. Please post relevant code here


Yes I did, here's the code.

<asp:UpdatePanel ID="upDefault" runat="server" UpdateMode="Conditional">
                    <asp:PostBackTrigger ControlID="UploadButton" />
                        <asp:FileUpload ID="HinhFU" runat="server" CssClass="largectl" ValidationGroup="UpByFile" />
                        <asp:RequiredFieldValidator ID="rfvFU" runat="server" ErrorMessage="*" ValidationGroup="UpByFile" ControlToValidate="HinhFU" >
                        <asp:Button runat="server" ID="UploadButton" Text="Upload" ValidationGroup="UpByFile" />

                    <asp:Image runat="server" ID="HinhSVImg" Width="100" Height="150" ImageUrl="" Visible="false" />


In the uploadbutton click I just check for HinhSV.HasFile, if yes then upload it with HinhSV.SaveAs().




In the uploadbutton click I just check for HinhSV.HasFile

I am not sure whether its your mistake while posting! But as per your code there is a fileupload control with id HinhFU and not HinhSV.Innocent