using html control to download file from client to server

G

Guest

Hi I am using the HtmlInputFile control to upload a file from a client to a
server. I have a browse to find the file on the server but need to create
the path dynamically as to were it will go based on some dropdown boxes, one
for the year and one for the month. This line saves the file so I am trying
to get the month and year from the dropdown boxes and put them in the month
and year variables but this does not work,
File1.PostedFile.SaveAs(("c:\\temp\\" + "\\" + month + "\\" + year +
Text1.Value))

These are the 2 lines I have to get the selected month and year but
var month=month_dropdrown.selectedindex;
var year=year_dropdrown.selectedindex;
but I get a compiler error, month_dropdown not defined. I am using
javascript.
I also tried printing out the variables using alert() but got a compiler
error, (not defined).
thanks
 
G

Guest

Are these Month and Year JScript variables.

Typically, you would write the upload function in your server side script.
All the processing of forming the path and file name needs to be done on the
server.

If you need syntax for that please let me know.
 
G

Guest

hi thanks for the response. Yes these are jscript variables. Yes if you
could provide syntax for processing of forming the path and file name (that
needs to be done on the server). Doesn't the javascript run on the client
machine?
thanks again,
 
G

Guest

actually I am running the script on the server I think,
<script language="javascript" runat="server">
 
G

Guest

You have to do the following to make it work -
1. On the HTMLInputFile set the runat property to server.
2. Add another button called upload.
3. In Click event on the server side for upload write the following
functionality -
MyFile.PostedFile.SaveAs("c:\temp\" & ...your logic to create the file based
on your requirements)

Please let me know if the above helps.
 
G

Guest

Hi thanks for the additional information. I think I almost have it working
but am having syntax issues building the MyFile.PostedFile.SaveAs("c:\temp\"
& ...your logic to create the file based on your requirements) line. I am
trying to build the path dynamically and have 2 dropdown boxes but can not
seem to get the selected value from these to append the path in the line
MyFile.PostedFile.SaveAs(). For the dropdown year box I have
<select name="year_dropdown">
<option value="2007" selected>2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option></select></p>
so when the file is saved I want it to go to (c:\2007\filename) if 2007 is
selected for example. I am doing the same thing with the month that is
selected.
 
R

Russell

Make your selects into <asp:DropDownList runat=server or at least make
them runat=server.

Otherwise the data isn't available server-side except through the
Request or Request.Form hashes.

string val = Request.Form("year_dropdown");
if (val != null)
{ ...

DropDownList has a SelectedValue property.
 
G

Guest

thanks for the additional information. I have the following for the dropdown
list
so not quite sure why I am still not able to get the values. I am trying to
get the values in a javascript section that is called when the use clicks a
button. Also for the javascript I have it running on the server,
<script language="javascript" runat="server">
*************below dropdown box description.
<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="07">2007</asp:ListItem>
<asp:ListItem Value="08">2008</asp:ListItem>
<asp:ListItem Value="09">2009</asp:ListItem>
</asp:DropDownList>
 
G

Guest

The statement below seems to work so will just use it, thanks.
year= Request.Form("DropDownList1");
 
G

Guest

thanks for the response, the statement below seems to be returning the
selected value.
var year= Request.Form("DropDownList1");
I currently have a browse to get the source file off of the client machine
and then
am using a text box for the user to type in a new file name. I would like
to strip off just the file name from what has been selected in the browse and
place it in the text box or just get rid of the text box so the user does not
have to retype it in (as the file name will not change). If you have any
suggestions on this, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top