Posting filepath in file upload control in .NET to the next page and uploading the file from second page

In our application (using C# .NET) there is a form with file upload options. After filling up the form details, the summary of the details need to be shown in the next page before committing the information into the database. Right now, Server.Control is used to transfer the contents to the next page and the form details are retrieved using Request.Form["control id"]. But this is not working for File upload control alone.
File upload can not be done in the first page itself, as the foreign key in File upload table gets updated only in second page after confirmation.
Therefore, is there a way to transfer the entire file path to the next page and retrieve it there so as to upload the file from the second page?
Thanks in advance.

0
giridharprasad
7/22/2008 4:32:31 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

6 Replies
2819 Views

Similar Articles

[PageSpeed] 58

Hi

use session

session["path"]=Fileupload1.PostedFile.FileName

 then next page

retrieve the file name

String spath=Session["path"].ToString()

 


Regards,
M.Venkatesan
My Blog : http://venkat-dotnetsamples.blogspot.com


Please remember to click “Mark as Answer” on the post that helps you,and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
venkatu2005
7/22/2008 4:57:19 AM

 hi giridharprasad,

u sohuld make use of this function to get the full path rather than only FileUpload1.PostedFile.FileName.

System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName)

Now if ur using Cross PostBack (using Sever.Transfer) then rather than using Session u can also use HttpContext.Current.Items.Add method

e.g. In case of Cross PastBack

In FirstPage

HttpContext.Current.Items.Add("path", IO.Path.GetFullPath(FileUpload1.PostedFile.FileName))

In Second Page

Dim strPath = HttpContext.Current.Items.Item("path").ToString() 

Otherwise u can make use of this also

Session("Path") = IO.Path.GetFullPath(FileUpload1.PostedFile.FileName)

 Dim strPath =  Session("Path").ToString()

 

I hope this will help u.

 


Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
Ahmedabad
0
Coool
7/22/2008 5:07:17 AM

Hi

Thanks for the code. Indeed, I require the full file path. When I tried your code, I got an error msg "the name IO does not exist in current context". Please let me know how I should resolve this error.

Thanks

0
giridharprasad
7/22/2008 5:46:56 AM

This is the code I am using as per your suggestion in the first page

protected void Issues_submit_Click2(object sender, EventArgs e)

{

//Session["filename"] = System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);

//HttpContext.Current.Items.Add("path", IO.Path.GetFullPath(FileUpload1.PostedFile.FileName));

Session["filename"] = IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);Server.Transfer("~/Confirmation.aspx",true);

}

 and I have th following code in Page Load event of next page

protected void Page_Load(object sender, EventArgs e)

{

if (Request.Params.Count > 0)

{

Issues_confirm_short_desc.Text = Request.Params.Get("Issues_issue_name");

//Issues_file_upload.Text = Request.Params.Get("Issues_Field1");

Issues_confirm_detailed_desc.Text = Request.Params.Get("Issues_issue_desc");

//Issues_file_upload.Text = Session["filename"].ToString();

//FileUpload1.PostedFile.FileName = Session["filename"].ToString();

string strPath = Session["Path"].ToString();

 I am able to retrieve all other values  like Issues_confirm_detailed_desc.Text and Request.Params.Get("Issues_issue_desc");

But Iam getting "The name IO does not exist in the current context" in both the cases.

 

0
giridharprasad
7/22/2008 6:15:49 AM

 Sorry to post my code in VB.NET,

try

System.IO.Path instead on IO.Path


Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
Ahmedabad
0
Coool
7/22/2008 6:30:36 AM

I have used the following code to achieve it

 In the first page

Context.Items["FileUpload1.PostedFile.FileName"] = System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);

and in the next page

Strpath = (string)Context.Items["FileUpload1.PostedFile.FileName"];

Issues_file_upload.Text = (string)Strpath;

Thanks for helping out

0
giridharprasad
7/22/2008 6:55:16 AM
Reply:

Similar Artilces:

Is there a way to automate uploading file in a web page using html file input control?
I used a form with a web browser control on it to automate the process of connecting to a website entering the login and password and finish the process of uploading a file.As you navigate to the upload page i can't get the input file control to work automatically because the value property is read only and here is the code HtmlDocument loginPage = wb.Documanet;loginPage.All["file1" ].SetAttributes("value", @"C:\A\A.txt");              //this doesn't work Your help is appreciated. Mark as an answer if it helps. ...

Auto create HTML page with the upload image file inside the page VB.NET
Hello guys, I want to create automatically an html page with the image i 've uploaded before. Any help ??? Thank you in advance Hi mate, you do not need create a html page per each image you upload to the server... only build an empty aspx page (viewer.aspx???) with an asp:image control...  and call it each time you needs it, let's see: 1.- create a property named myImage in the page you upload the image (ie. source.aspx) Public ReadOnly Property myimage() As StringGetReturn "uploaded_image_name"End GetEnd Property 2.- add this tag into your asp...

After Uploading File, Refreshing Page causes file to upload again
As my subject says, after using the FileUpload control to send a file to my server, if the user presses F5 to refresh the page, the file will be uploaded again. The upload control does not list a file, but the tracing on the page does list items under Content_Length and Content_Type under Headers Collection and Server Variables. CONTENT_LENGTH570032CONTENT_TYPEmultipart/form-data; boundary=---------------------------7d6119a16138cI tried clearing these out by using the following commands after my initial file upload without success:Response.ContentType = null;Response.ClearContent();Resp...

How to upload an Outlook Message in File Upload control in .Net
Hi All, Is it possible to upload an outlook message from outlook in File Upload control.Please don't suggest to save the message onto the desktop and then upload it!   What I am after is really navigating to the outlook folders through the File Upload control and upload a message.  Thanks guys   If there is a way to do it, but it could be used to maliciously read someone's email folders, forgive me if I hope no one answers you. :)...

Upload all files in folder with file upload control
H i I'm trying to upload all files to a wesite that is in a specific local folder. My code workes fine when I run it locally but when I upload it it fails. I think it looks for the files to upload on the web server and thus cannot find it.  1 Dim files() As String 2 folderExists = System.IO.Directory.Exists(foldername) 3 If folderExists = False Then 4 Label1.Text = "Folder does not exist. Did you enter a folder name or just a file name ?" 5 Exit sub 6 End If 7 files = System.IO.Directory.GetFiles(foldername) 8 For...

How Do I Enable A File Upload Control When Another File Upload Control Has A Value?
Hi There,Thanks you for taking the time to read this post.  I am quite new to programming and have searched the net and experimented with my own code but not been able to get it to work yet.I am creating a simple CMS for a friends site and my friend wants to be able to upload 9 images per page.I have created an asp.net form with 9 file upload controls.  I want 1 control to be enabled by default and the other 8 controls disabled until the previous control has a value.  I have set the default setting in visual studio without any problem.My first thought was to double cli...

Deleting A File Uploaded Through File Upload Control
Hello, I have a form which allows a user to upload a file to a virtual drive on our server using the following code: fileInvoice.SaveAs(ConfigurationManager.AppSettings.Get("DocumentPath") + strFileName); //Document Path is defined in the web.config file How can I safely allow a form on a web page to delete the file if they know the exact name of the file. I don't want them to be able to do a wildcard match like test* thanks in advance, mitch  Peace be on you brother, so you want to safely delete the file which the name you know. OK I consider that the name ...

Upload and Show Power Point File in .NET Page
hi i want to let my users to upload their power point files to show on net. I think i can handle the uploading but i dont know how to show that ppt file in a page. I also want to put next and previous buttons and full screen button in my ppt shower. Is there any example on that? to understand easily what i want u can visit this page: http://www.authorstream.com/Presentation/Elliott-30963-ASPNETAJAX-sunum-ASP-NET-AJAX-ileWeb-Uygulamalar-Geli-tirmek-Ajanda-Nedir-Asenkron-JavaScript-XML-Klasik-al-ma-Mod-as-Entertainment-ppt-powerpoint/   In the example you'te referring, a powerp...

How to identify the original file type and restrict the file uploading while using file upload control
 Hi asp.net , I am uploading a file using FileUpload control in asp.net using vb.net.I wrote the code to upload only PDF files. the user can change the extension and change to PDF . I have to check is the file original PDF or not then i have to upload the PDF files only . How to do this ??  Hi, Check the file Mime type for "application/pdf" by looking at the:  FileUpload1.PostedFile.ContentType RegardsSmcoxonNo Gem is ever polished without some friction. Hi smcoxon , Thanks For Replying ,But i found that there is no use using PostedFil...

File upload in chunks
So I downloaded the files from codeproject for the "upload files in chunks" application at http://www.codeproject.com/KB/XML/MTOMWebServices.aspx?df=100&forumid=250646&exp=0&select=2292508 I've adapted the c# code into vb.net and tests I run locally show it working ok.  Trouble is, the client side was written for windows application level client, not web, so I'm wondering if anyone has already got a bit of client side web coding to take an uploaded file and split it into chunks that is compatible with this web service at all? Well I use MTOM and WSE 3.0 ...

Combine web form data with file upload in single page.
I'd like to have users fill out an online form as well as upload a file - in a single page. Any advice on the best way to approach this using C#?Thanks,Doug Use the FileUpload Control (ASP.NET 2.0) in your form. Vikram.S, DeveloperDiscountASP.NETInnovative ASP.NET Hosting & SQL Hosting Check out the below example Upload Files ASP.NET/C# HCHaissam Abdul MalakMCAD.NET| Blog | Thanks for the advice - that was easy. On to the next problem...  is there a way to have the uploaded file land in a directory of my choosing?  It looks like the file will upload to whatever di...

Trying to create a FIle Upload page using vb.net
Can someone give me some advise on what I may be doing wrong in creating the file upload below. I'm trying to create a file upload page for a site that I'm developing, and whenever I click the  "Upload Image Button" nothing happens....the image that I'm trying to upload doesn't appear as expected. I have included the VB.NET code below. Thanks  code for uploadfile.aspx.vb Public Class uploadfile1 Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private S...

"Bug" with file upload control and multi-page forms
I'm not 100% sure if this is a bug or expected functionality, but I'm leaning towards a bug because what I'm trying to do seems to be something that's not too unusual. I've noticed that if you're doing a multi-page ASP.NET AJAX form the File Upload control does not work as expected. If the File Upload is not on the initally rendered page of the form it will not operate. Here's the scenario I found it in: I have a multiview control which is within an update panel. On the 2nd view there is a file upload control. The initial postback to upload a file will r...

Net.WebClient.Upload file method
HiI am loading a file from a client pc to a web server using the Net.WebClient classThe code is working like this: Dim uploader As New Net.WebClientuploader.UploadFile(baseAddress + "/ChequeReceipt.aspx", "c:\mypicture.jpg")The question I have is how can I introduce security checks in the ChequeReceipt.aspx web page?ie I would like to check something such as a valid user id or password so that only my application can call the ChequeReceipt.aspx web page and no one else canie in my page_load event of ChequeReceipt.aspx the following code appears/* SOME SECURITY CHECKING?????? */ Upload...

Web resources about - Posting filepath in file upload control in .NET to the next page and uploading the file from second page - asp.net.web-forms

Uploading and downloading - Wikipedia, the free encyclopedia
Examples of a remote system from which a download might be performed include a web server , FTP server, email server, or other similar systems. ...

Facebook Lets You Tag Photos While They're Uploading
Facebook now lets you add tags to photos before they're finished uploading.

Facebook for iPhone 3.0 to Include Video Uploading for 3GS Owners
We’ve heard a lot of people say the iPhone’s built-in support for YouTube video uploading is going to make a huge impact on the number of people ...

Defence bureaucrat pleads guilty to uploading secret document online
... embarrassing security breach with &quot;Five Eyes&quot; intelligence document. A former junior Defence bureaucrat has pleaded guilty to uploading ...

Uploading Bautista bat flip GIFs could get you sued under TPP, copyright activists warn
Copyright activists say Canadians could face lawsuits, fines or worse for ripping the latest Justin Bieber CD or uploading an animated GIF of ...

Xiaomi apologizes for uploading address book data from smartphones without permission
Former Android head and Xiaomi VP Hugo Barra has apologized to owners of its smartphones for "any concern caused" by collecting contact data ...

Senator calls for FTC investigation of Apple and Google over stealth photo uploading capabilities
Is this how we’ll have to open apps in the future? When we broke the news that iOS (and later Android) apps could upload your photo library (along ...

YouTubers Now Uploading Over 35 Hours Of Video Per Minute!
This week YouTube's got some big news! YouTubers are now uploading over 35 hours of video per minute, up from 24 hours a minute in March.

Google Play Books updated with new design, PDF and EPUB uploading
Caught up in all of the hullabaloo around the keynote, Google Play Books received a notable update in the Play Store to not only bring new UI ...

Twitter rolling out group messaging, 30-second video uploading
Fast Company Twitter rolling out group messaging, 30-second video uploading Android Community Different social networks are doing everything ...

Resources last updated: 11/23/2015 9:55:46 PM