Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2007, 09:59 AM
FT FT is offline
Authorized User
 
Join Date: Oct 2005
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default FileUploader

I am trying to get the url from the FileUploader control to appear in the ImageUrl textlabel. So I don't have to copy and paste the url in to the textlabel for a product.

How Can I do this ?

any comment?

Or maby some code that will do the trick


 
Old June 25th, 2007, 05:28 PM
Authorized User
 
Join Date: May 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello,

this is not perhaps the good solution but it's work and this is what you must to do :

add this event handler to your ManageCategiries.aspx.cs file :

protected override void OnPreRender(EventArgs e)
     {
         if (Session["fileUrl"] != null)
             ((TextBox)dvwCategory.FindControl("txtImageU rl")).Text = (string)Session["fileUrl"];
        
         base.OnPreRender(e);
     }

and modify your UploadFile_Click event handler like this :

protected void UploadFile_Click(object sender, ImageClickEventArgs e)
     {
         if (filUpload.PostedFile != null && filUpload.PostedFile.ContentLength > 0)
         {
             try
             {
                 // if not already present, create a directory named /Uploads/<CurrentUserName>
                 string dirUrl = (this.Page as EB.Eurobourse.UI.BasePage).BaseUrl +
                     "Uploads/" + this.Page.User.Identity.Name;
                 string dirPath = Server.MapPath(dirUrl);
                 if (!Directory.Exists(dirPath))
                     Directory.CreateDirectory(dirPath);
                 // save the file under the user's personal folder
                 string fileUrl = dirUrl + "/" + Path.GetFileName(filUpload.PostedFile.FileName);
                 filUpload.PostedFile.SaveAs(Server.MapPath(f ileUrl));

                 lblFeedbackOK.Visible = true;
                 lblFeedbackOK.Text = "File successfully uploaded: " + fileUrl;
                 Session["fileUrl"] = fileUrl; //Add this line
             }
             catch (Exception ex)
             {
                 lblFeedbackKO.Visible = true;
                 lblFeedbackKO.Text = ex.Message;
             }
         }
     }

cheers.
 
Old June 26th, 2007, 10:33 AM
FT FT is offline
Authorized User
 
Join Date: Oct 2005
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes Great this works.

But is it good to save the image url in a session ?
 
Old June 26th, 2007, 12:28 PM
Authorized User
 
Join Date: May 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

this is solution without using Session :

protected override void OnPreRender(EventArgs e)
       {
           if (HttpContext.Current.Items["url"] != null)
              ((TextBox)dvwCategory.FindControl("txtImageUrl")). Text = (string)HttpContext.Current.Items["url"];
           base.OnPreRender(e);
       }

protected void UploadFile_Click(object sender, ImageClickEventArgs e)
       {
           if (filUpload.PostedFile != null && filUpload.PostedFile.ContentLength > 0)
           {
               try
               {
                   // if not already present, create a directory named /Uploads/<CurrentUserName>
                   string dirUrl = (this.Page as EB.Eurobourse.UI.BasePage).BaseUrl +
                      "Uploads/" + this.Page.User.Identity.Name;
                   string dirPath = Server.MapPath(dirUrl);
                   if (!Directory.Exists(dirPath))
                       Directory.CreateDirectory(dirPath);
                   // save the file under the user's personal folder
                   string fileUrl = dirUrl + "/" + Path.GetFileName(filUpload.PostedFile.FileName);
                   filUpload.PostedFile.SaveAs(Server.MapPath(fileUrl ));
                   lblFeedbackOK.Visible = true;
                   lblFeedbackOK.Text = "File successfully uploaded: " + fileUrl;
                   HttpContext.Current.Items.Add("url", fileUrl);
               }
               catch (Exception ex)
               {
                   lblFeedbackKO.Visible = true;
                   lblFeedbackKO.Text = ex.Message;
               }
           }
       }

cheers.

 
Old June 26th, 2007, 02:46 PM
FT FT is offline
Authorized User
 
Join Date: Oct 2005
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great thanks That works fine.
:-)






Similar Threads
Thread Thread Starter Forum Replies Last Post
FileUploader user control chapter 5 psychonet BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 June 5th, 2007 08:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.