943,106 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 684
  • ASP.NET RSS
Feb 9th, 2010
0

Uploading file and dispaly name of flie and remove Link.

Expand Post »
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.
ASP.NET Syntax (Toggle Plain Text)
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. LinkButton1.Visible = false;
  4. label2.Visible = false;
  5. }
ASP.NET Syntax (Toggle Plain Text)
  1. if (FileUpload1.HasFile)
  2. try
  3. {
  4. FileUpload1.SaveAs("e:\\parimal\\" + FileUpload1.FileName);
  5. Label1.Text = "File name: " + FileUpload1.PostedFile.FileName + "<br>" +
  6. FileUpload1.PostedFile.ContentLength + " kb<br>" +
  7. "Content type: " +
  8. FileUpload1.PostedFile.ContentType;
  9.  
  10. flag = 1;
  11. }
  12. catch (Exception ex)
  13. {
  14. Label1.Text = "ERROR: " + ex.Message.ToString();
  15. }
  16. else
  17. {
  18. Label1.Text = "You have not specified a file.";
  19. }
  20. if (flag == 1)
  21. {
  22. label2.Text = FileUpload1.PostedFile.FileName;
  23. label2.Visible = true;
  24. LinkButton1.Visible = true;
  25. flag = 0;
  26. }
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....
Reputation Points: 9
Solved Threads: 0
Junior Poster in Training
Pari13 is offline Offline
59 posts
since Jan 2010
Feb 9th, 2010
0
Re: Uploading file and dispaly name of flie and remove Link.
>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.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,524 posts
since Oct 2008
Feb 11th, 2010
0
Re: Uploading file and dispaly name of flie and remove Link.
Click to Expand / Collapse  Quote originally posted by adatapost ...
>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........
Reputation Points: 9
Solved Threads: 0
Junior Poster in Training
Pari13 is offline Offline
59 posts
since Jan 2010
Feb 11th, 2010
0
Re: Uploading file and dispaly name of flie and remove Link.
>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

ASP.NET Syntax (Toggle Plain Text)
  1. <head runat="server">
  2. <title>Sample Page</title>
  3. <script type="text/javascript">
  4. function DoSubmit(){
  5. var form=document.getElementById("form1");
  6. form.submit();
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. <form id="form1" runat="server">
  12. <div>
  13. <asp:FileUpload ID="FileUpload1" runat="server" onChange="DoSubmit();" />
  14. </div>
  15. </form>
  16. </body>

.cs code-behind file

ASP.NET Syntax (Toggle Plain Text)
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (FileUpload1.HasFile)
  4. {
  5. FileUpload1.SaveAs(MapPath("~/folderName/" + FileUpload1.FileName));
  6. }
  7. }
Last edited by adatapost; Feb 11th, 2010 at 10:08 am.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,524 posts
since Oct 2008
Feb 13th, 2010
0

Thanks ,regards......

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.......


Click to Expand / Collapse  Quote originally posted by adatapost ...
>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

ASP.NET Syntax (Toggle Plain Text)
  1. <head runat="server">
  2. <title>Sample Page</title>
  3. <script type="text/javascript">
  4. function DoSubmit(){
  5. var form=document.getElementById("form1");
  6. form.submit();
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. <form id="form1" runat="server">
  12. <div>
  13. <asp:FileUpload ID="FileUpload1" runat="server" onChange="DoSubmit();" />
  14. </div>
  15. </form>
  16. </body>

.cs code-behind file

ASP.NET Syntax (Toggle Plain Text)
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (FileUpload1.HasFile)
  4. {
  5. FileUpload1.SaveAs(MapPath("~/folderName/" + FileUpload1.FileName));
  6. }
  7. }
Reputation Points: 9
Solved Threads: 0
Junior Poster in Training
Pari13 is offline Offline
59 posts
since Jan 2010
Dec 6th, 2010
0
Re: Uploading file and dispaly name of flie and remove Link.
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['ufile']['name'];

// 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['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";

//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
}
else
{
echo "Error";
}
}
?>
Reputation Points: 0
Solved Threads: 3
Junior Poster in Training
crishjeny is offline Offline
98 posts
since Nov 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: ASP NET Dynamic Buttons Event Handler‏
Next Thread in ASP.NET Forum Timeline: row not inserting





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC