Dear All,
Have good day,

I am trying to attatch file like yahoomail attatchement ,it means displaying name of file and Remove link after Button_click event fire.

protected void Page_Load(object sender, EventArgs e)
    {
        LinkButton1.Visible = false;
        label2.Visible = false;
    }
if (FileUpload1.HasFile)
            try
            {
                FileUpload1.SaveAs("e:\\parimal\\" + FileUpload1.FileName);
                Label1.Text = "File name: " + FileUpload1.PostedFile.FileName + "<br>" +
                     FileUpload1.PostedFile.ContentLength + " kb<br>" +
                     "Content type: " +
                     FileUpload1.PostedFile.ContentType;

                flag = 1;
            }
            catch (Exception ex)
            {
                Label1.Text = "ERROR: " + ex.Message.ToString();
            }
        else
        {
            Label1.Text = "You have not specified a file.";
        }
        if (flag == 1)
        {
            label2.Text = FileUpload1.PostedFile.FileName;
            label2.Visible = true;
            LinkButton1.Visible = true;
            flag = 0;
        }

Its work properly for one file ,but if I want to add one then it not work
so plz if U have solution for displaly all the file dynamicallly below of "FILE" control in asp.net
Thanks in Advanced....

Recommended Answers

All 5 Replies

>displaly all the file dynamicallly below of "FILE" control in asp.net

Sorry, I'm not quite following the problem. There is no "FILE" control in asp.net.

>Uploading file and dispaly name of flie and remove Link.

You may use System.Directory.GetFiles(path) method to have a list of files.

>displaly all the file dynamicallly below of "FILE" control in asp.net

Sorry, I'm not quite following the problem. There is no "FILE" control in asp.net.

>Uploading file and dispaly name of flie and remove Link.

You may use System.Directory.GetFiles(path) method to have a list of files.

Oh....no ,,actully its Fileupload control in asp.net that is used to uploading file....
and i am able to do attach file by click event on Button.but i want this can done by only click on OPEN button of DialogBox and not on asp server control like Button.

if U understand then plz reply me as u can........

>but i want this can done by only click on OPEN button of DialogBox and not on asp server control like Button.

Subscribe JavaScript event onchange.

.aspx page

<head runat="server">
    <title>Sample Page</title>
    <script type="text/javascript">
       function DoSubmit(){
           var form=document.getElementById("form1");
           form.submit();
       }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server"  onChange="DoSubmit();"  />
    </div>
    </form>
</body>

.cs code-behind file

protected void Page_Load(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(MapPath("~/folderName/" + FileUpload1.FileName));
        }
    }

Wow.......,
Thank you ,Thank you So much MR.adatapost.
IT work very well .....and i am very very happy to successing it....
thank u so much once again.......

>but i want this can done by only click on OPEN button of DialogBox and not on asp server control like Button.

Subscribe JavaScript event onchange.

.aspx page

<head runat="server">
    <title>Sample Page</title>
    <script type="text/javascript">
       function DoSubmit(){
           var form=document.getElementById("form1");
           form.submit();
       }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server"  onChange="DoSubmit();"  />
    </div>
    </form>
</body>

.cs code-behind file

protected void Page_Load(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(MapPath("~/folderName/" + FileUpload1.FileName));
        }
    }

Hi

You can refer following code for Uploading file and dispaly name of flie and remove Link.


<?php

// Your file name you are uploading
$file_name = $HTTP_POST_FILES;

// random 4 digit to add to our file name
// some people use date and time in stead of random digit
$random_digit=rand(0000,9999);

//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables

$new_file_name=$random_digit.$file_name;

//set where you want to store files
//in this example we keep file in folder upload
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES, $path))
{
echo "Successful<BR/>";

//$new_file_name = new file name
//$HTTP_POST_FILES = file size
//$HTTP_POST_FILES = type of file
echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES."<BR/>";
echo "File Type :".$HTTP_POST_FILES."<BR/>";
}
else
{
echo "Error";
}
}
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.