File Upload routine & File download routine

Two questions. For both, Asp.net with vb.net codebehind.

#1. Given the following (1) a web form with an upload file control, (2) a string variable SocialSecurityVar that holds a 9-digit social security number that is fetched from the session state, and (3) a string variable ExtVar with no initial value
how would i code a routine as follows:
1. user clicks browse
2. user selcts a file to upload to server, clicks ok
3. routine reads string variable SocialSecurityVar (say from form or session state) and in a pre-existing direcotry named \DOCS searches for the subdirectory named \DOCS\XXXXXXXXX where XXXXXXXXXX is the string in the SocSecVar variable. If there is no Subdirectory XXXXXXXXX in DOCS, routine creates subdirectory DOCS\XXXXXXXXX where XXXXXXXXX is the string in SocialSecurityVar
4. Server reads the extension from the filename and stores it in string variable ExtVar
5. Server writes the uploaded file to the DOCS\XXXXXXXXXX\ directory to a file named XXXXXXXXX.nnn where XXXXXXXXX is the string in SocSecVar and nnn is the string in ExtVar

Example 1: session stored social security number 123456789. User clicks browse. Selects resume.doc to upload. Routine creates folder DOCS\123456789\ and uploads resume.doc to folder and names the file 123456789.doc

Example 2: session stored social security number 987654321. User clicks browse. Selects resume.doc to upload. Routine finds folder DOCS\987654321\ exists and uploads resume.doc to folder and names the file 987654321.doc, overwriting any existing file of that name.

 
Question 2. I have a button named btnDownload. Given String variable SocialSecurityVar how would i code a routine that when button is clicked

1. searches in the \DOCS\ direcotry on the server for a subdirectory with name = string in SocialSeciurityVar
2. If direcory exsists, server finds the newest file in that directory and opens a download that file dialog on the users browser.

 

Example 1: sessin stored social security number is 123456789. User clicks Download. Routine searches for and finds a directory DOCS\123456789\. Routine determines 123456789.pdf is the newest file. Opens Download 123456789.pdf? dialog.

 Thanks!!!

0
steverosen9
2/11/2008 10:59:04 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

3 Replies
981 Views

Similar Articles

[PageSpeed] 33
Get it on Google Play
Get it on Apple App Store

Hi Steve,

I will try to help you here.

Here is the solution for your upload problem:

 

Imports System.IO

Partial Class _Default
    Inherits System.Web.UI.Page

    'UPLOAD
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Loading SSN in session
        Session("SSN") = "123456789"


        If FileUpload1.HasFile Then
            'If directory exist upload the file
            If (Directory.Exists("D:\" & Convert.ToString(Session("SSN")))) Then
                FileUpload1.SaveAs("D:\" & Convert.ToString(Session("SSN")) & "\" & FileUpload1.FileName)

            Else
                'Otherwise, create the directory and upload the file
                Directory.CreateDirectory("D:\" & Convert.ToString(Session("SSN")))
                FileUpload1.SaveAs("D:\" & Convert.ToString(Session("SSN")) & "\" & FileUpload1.FileName)
            End If

            'Uncomment this portion to rename the file according to SSN. You might need to change the path.
            'Dim TheFile As FileInfo = New FileInfo(MapPath(".") & "\" & FileUpload1.FileName)
            'If TheFile.Exists Then
            '    File.Move(MapPath(".") & "\" & FileUpload1.FileName, MapPath(".") & "\" & Convert.ToString(Session("SSN")))
            'End If

        End If

    End Sub

I'm still working on the download portion. I will write back tomorrow. Hang in there. 

 

 


Don't forget to click "Mark as Answer" on the post that helped you.
0
amensi
2/12/2008 1:13:08 AM

 amensi, thanks man. I am going to study what you wrote and figure out exactly what you are doing here. I've been trying to do this for a week. finally some clarity. priceless! 

Steve


 

0
steverosen9
2/12/2008 1:53:28 AM

No problem. If you have any questions, don't hesitate to ask.




Don't forget to click "Mark as Answer" on the post that helped you.
0
amensi
2/12/2008 3:59:56 AM
Reply:

Similar Artilces:

Processes file content before upload (from file upload form)
Hello I have a web aplication that needs to process file content (client side) before uploading them to server. May be I have to use file upload form and somehow read files and sign them on submit event I'm not sure how (and can I) do this in Firefox extension? I prefer to use browser functionality for file upload rather than make my own HTTP connection from my extension. I also prefer not to write any user interface. On 4/7/10 7:27 AM, Юлиян wrote: > I have a web aplication that needs to process file content (client > side) before uploading them to server. htt...

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

My form can do a file upload but can't do a file download (from a sql image column)
Hi everyone, I've created an ASP.NET C# form that displays a record from a SQL database on the web. I can get everything to load fine except for a file stored in an "image" (datatype) field. What I want is the page to display either a picture or a link or something that the user can click to download the file. I can't seem to figure out is: 1. what type of object to put in the form (text link, image, etc.) to allow for a downloadable file. 2. how to assign the file contained in the image column to some sort of variable. For the other columns in the sql table I...

How to File Upload and Download file ( .doc/.pdf/.gif/.exl) from server web browser C#
How to File Upload and Download file ( .doc/.pdf/.gif/.exl) from server web browser Please help me Thanking you Saikat   Uploading: Try a Google search for upload file web server asp.net c#. Download: <a href="http://www.mydomain.com/pathtofile">Download Me</a> HTH,RyanRyan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question HiI want to download this logo.gif . It is possable to download. Download: <a href="http://www.google.com/intl/en/images/logo.gif">Download Me</a> and How to File Upload .doc/.pdf/.gif/.exl file we...

upload files and downloading a pdf file
what data type am i going to put to my uploadedFiles column in my database... uploaded files are in document format or .txt  also.. how can i make those files converted into pdf files.. also enable users to download it.. tnx!!! forums.asp.net = "great help"red is the name What kind of database? With SQL Server, its an Image datatype.  If you want ot convert it to a PDF, you need to look at third party add-ons.  There is nothing in the .NET Framework that handles PDFs specifically. Regards Mike [MVP - ASP/ASP.NET]My site varbinary is the datatype you wis...

vb.net web project
Hi All, I have a situation in my web application whereby after accepting username & password from user I want to create a text file on web server and then upload it to somewhere via ftp? Any one can help me doing this please? Best Regards, Usman Why dont you have a Web Service on the server that creates the text file and then make an instance of it when someone login that is creating the file.Mikael Söderström...

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server.http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspxPlease Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.comhttp://www.mitatdotnet.blogspot.com As always there are many ways and which ...

File Upload Problem
Hi Everyone,I was grateful to be able to download the code for uploading files into a folder from Sreedhar's web page. The code works well, but whenever there is another new file with the same file name being uploaded into the destination folder, the old file will be replaced. I am wondering if there is any way to solve this problem (How about adding a number to the new file's name, e.g. File1.doc, if there is an existing File.doc?) I am an absolute beginner and any help is deeply appreciated.The original code is as follows: <%@ Page Language="VB" MasterPageFile="~/MasterP...

File Upload Control & File Path
when using the asp.net 2.0 file upload web control, i need a user to be able to specify a file to upload from their PC, but whenever I select the full path of the imported file, it returns something likeC:\Documents and Settings\User\Desktop\ (my application home is on the desktop) ..The path displays C:\file.txt, but it always changes when i print the path.. What is going on??  My Code: Dim filePath As String = (Path.GetFullPath(fupBrowse.PostedFile.FileName))-Dave hi, try this  Dim filePath As String        filePath = FileUpload...

Downloading form. How to hide form after file is downloaded.
 Hi,I've this problem:I've form which user fills before downlaod file:<%= Resources.Resources.YourName %>*:<asp:Panel ID="_getInfoPanel" runat="server">  Your Name:<asp:TextBox ID="_yourNameTB" runat="server" /> ...<asp:Button ID="_addButton" runat="server"               Text="<%$ Resources:Resources, Continue %>" onclick="_addButton_Click" /> </asp:Panel> and when _addButton(in event h...

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

upload file by file
hi all,   we have project, local in server, more then one people do the update, let's say, if all file local in test, I did the modify in local and build and upload the whole test file into service, it work fine. but if I only upload helloone.aspx. and its Vb file (under test) into service, it did not work( the VB code) , is that a way to only upload file by file to service, thank you   If I understand your problem correctly, I think the problem that you may be having is that after pages are compiled locally they are not being compiled for the entire site.  I would su...

Uploading files on a web form
HI everyone, Being new to ASP.Net the only thing I know is that web forms don't support drag and drop and that they don't support the system.windows.form openFileDialog method. so, my question is: I need to have a button display a modal pop up window (with a fixed size) where the user can find a file to upload, which by the way I have no clue how to do. Then, I need to display the file's path and name on a textbox to let the user know that the file has been selected and upload the file to a new location. I appreciate any help. Thanks, Hi, To have a file upload control, yo...

Upload file from web form
Hi, I am using master and child page combination. I want to upload a file from web form (child page) to the server. How can I do this? thanks in advance.feed the creative machine I got it.Use ASP .net 2.0 fileupload control.Use the SaveAs method of the control to save the file on server.Its really simple.feed the creative machine...

Web resources about - File Upload routine & File download routine - asp.net.web-forms

Don't Download This Song - Wikipedia, the free encyclopedia
" Don't Download This Song " is the first single from "Weird Al" Yankovic 's 12th studio album Straight Outta Lynwood . The song was released ...

Facebook Adds To Download Your Information
Facebook increased the amount of information users can access when they download their account histories using the social network’s Download ...

Download the Facebook IQ digital magazine - Facebook for Business
The Facebook IQ digital magazine puts all the insights, best practices and key stats in one place. Download it on your mobile and read it anywhere. ...

Downloads
Download previous versions of the Facebook for iOS SDK.

‘Silent updates’ for Android download latest version of Facebook without Google Play
... users to receive app updates without going through the Google Play store. Some Android users are now receiving “silent updates,” which download ...

Lifehacker, tips and downloads for getting things done
Lifehacker curates tips, tricks, and technology for living better in the digital age.

Technology Product Reviews, News, Prices & Downloads - PCMag.com - PC Magazine
PC Magazine is your complete guide to PC computers, peripherals and upgrades. We test and review computer- and Internet-related products and ...

Indie Music News, MP3 Downloads, Music Videos, Reviews - Stereogum
MP3s downloads, music videos, concert reviews, tour dates and contests. Updated regularly.

RN Download ThisShow (@RNDownload) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here RN Download ThisShow @ RNDownload ...

Hey Siri, download Cortana to my iPhone later today, would you?
... , Cortana iPhone , Siri For more news on Apps , Siri , and Cortana continue reading at 9to5Mac . What do you think? Discuss "Hey Siri, download ...

Resources last updated: 12/21/2015 7:44:25 AM