473,249 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,249 software developers and data experts.

Upload and dropdownlist from folder

Bob
I've made an upload function saving to a specific folder and dropdownlist
reading and listing files from the folder.
When I upload, the list is rendered a second time in the dropdownlist with
the uploaded file only being displayed in the second list. I would like to
avoid the dropdown being filled twice but my knowledge is still pretty
limited so I would be gratefull for help. Also if someone could perhaps
point me to how I make the just uploaded file the selected one in the
dropdownlist it would be perfect. It should be used later on in a Formview
inserting records into a db. But I need to get over this first issue before
I move on.

Here's some code I guess it's the Formview1_PreRender stuff that's the issue
it's logical that it renders it twice but what I should do instead I cannot
figure out.

<script language="VB" runat="server">
Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim FileUpLoad1 As FileUpload =
CType(FormView1.FindControl("FileUpLoad1"), FileUpload)
Dim Labeltxt As Object = FormView1.FindControl("Label1")
If FileUpLoad1.HasFile Then
'Uncomment this line to Save the uploaded file
FileUpLoad1.SaveAs("d:\web\pics\" & FileUpLoad1.FileName)
Labeltxt.Text = "Received " & FileUpLoad1.FileName & " Content
Type " & FileUpLoad1.PostedFile.ContentType & " Length " &
FileUpLoad1.PostedFile.ContentLength
Else
Labeltxt.Text = "No uploaded file"
End If

End Sub

Sub Formview1_PreRender(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles FormView1.PreRender

Dim di As New System.IO.DirectoryInfo("d:\web\pics\")
Dim fiArr As System.IO.FileInfo() = di.GetFiles()
Dim fi As System.IO.FileInfo
If FormView1.CurrentMode = FormViewMode.Edit Or
FormView1.CurrentMode = FormViewMode.Insert Then
Dim SectionDropDownList As DropDownList
SectionDropDownList = FormView1.FindControl("PicTextBox")
SectionDropDownList.Items.Insert(0, New ListItem("--- Choose
Picture ---"))

For Each fi In fiArr
SectionDropDownList.Items.Add("/pics/" + fi.Name)
Next fi

End If
End Sub
</script>
<form id="form1" runat="server">
<asp:FormView ID="FormView1" DefaultMode="Insert" runat="server">
<InsertItemTemplate>
<asp:DropDownList ID="PicTextBox" runat="server">
</asp:DropDownList>
<br />
<asp:Label id="LabelBilledeupload" runat="server" width="70px"
text="Upload billede:" />

<asp:FileUpLoad id="FileUpLoad1" runat="server" /> <asp:button
id="Button1"
runat="server"
text="Upload billede"
onclick="Button1_Click" /><br />
<asp:Label id="Label1" runat="server" />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
</asp:FormView>
</form>
Apr 28 '06 #1
1 2342
Use Page.IsPostback method to check if the page is loaded for first time or
not.

About selecting the file, iterate through the Dropdownlist's Listitem
collection and check for the file which u've uploaded, and use selectedindex
to set the item.

"Bob" <do*************@usa.net> wrote in message
news:eT**************@TK2MSFTNGP02.phx.gbl...
I've made an upload function saving to a specific folder and dropdownlist
reading and listing files from the folder.
When I upload, the list is rendered a second time in the dropdownlist with
the uploaded file only being displayed in the second list. I would like to
avoid the dropdown being filled twice but my knowledge is still pretty
limited so I would be gratefull for help. Also if someone could perhaps
point me to how I make the just uploaded file the selected one in the
dropdownlist it would be perfect. It should be used later on in a Formview
inserting records into a db. But I need to get over this first issue
before I move on.

Here's some code I guess it's the Formview1_PreRender stuff that's the
issue it's logical that it renders it twice but what I should do instead I
cannot figure out.

<script language="VB" runat="server">
Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim FileUpLoad1 As FileUpload =
CType(FormView1.FindControl("FileUpLoad1"), FileUpload)
Dim Labeltxt As Object = FormView1.FindControl("Label1")
If FileUpLoad1.HasFile Then
'Uncomment this line to Save the uploaded file
FileUpLoad1.SaveAs("d:\web\pics\" & FileUpLoad1.FileName)
Labeltxt.Text = "Received " & FileUpLoad1.FileName & " Content
Type " & FileUpLoad1.PostedFile.ContentType & " Length " &
FileUpLoad1.PostedFile.ContentLength
Else
Labeltxt.Text = "No uploaded file"
End If

End Sub

Sub Formview1_PreRender(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles FormView1.PreRender

Dim di As New System.IO.DirectoryInfo("d:\web\pics\")
Dim fiArr As System.IO.FileInfo() = di.GetFiles()
Dim fi As System.IO.FileInfo
If FormView1.CurrentMode = FormViewMode.Edit Or
FormView1.CurrentMode = FormViewMode.Insert Then
Dim SectionDropDownList As DropDownList
SectionDropDownList = FormView1.FindControl("PicTextBox")
SectionDropDownList.Items.Insert(0, New ListItem("--- Choose
Picture ---"))

For Each fi In fiArr
SectionDropDownList.Items.Add("/pics/" + fi.Name)
Next fi

End If
End Sub
</script>
<form id="form1" runat="server">
<asp:FormView ID="FormView1" DefaultMode="Insert" runat="server">
<InsertItemTemplate>
<asp:DropDownList ID="PicTextBox" runat="server">
</asp:DropDownList>
<br />
<asp:Label id="LabelBilledeupload" runat="server" width="70px"
text="Upload billede:" />

<asp:FileUpLoad id="FileUpLoad1" runat="server" /> <asp:button
id="Button1"
runat="server"
text="Upload billede"
onclick="Button1_Click" /><br />
<asp:Label id="Label1" runat="server" />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
</asp:FormView>
</form>

Apr 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Smith | last post by:
Hi, I'm using the Persists ASPUpload component to upload files to various sub-directorys in the root of my website. I have written a short bit of code for this but it always uploads to the root...
5
by: tolgademirel | last post by:
I am creating a web application which needs to access data which resides on the client's computer. The data is a bunch of text files that are stored in a folder. I need all of those text files....
0
by: SEMIH DEMIR | last post by:
Sitelerden birinde verilen yabancı kaynakli bir scriptti duzenledim yanlız birseyin içinden bir turlu cıkamadım işin aslı ilk defa persistin upload componentini kullanacam yanlız suanki haliyle...
1
by: JimmySlam | last post by:
Hi I am triyingo to upload a file with ASPUPLOAD which works fine the only problem I need to change the folder where is going to be uploaded. I tried with folder =...
1
by: Alex | last post by:
I am having issues with a script to upload files from a client to a webserver. The problem is not with the actual upload but with where it uploads. The whole process is supposed to create a...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
4
by: Tony B | last post by:
I've moved an existing site (which I didn't write) from a apache/php/mysql host under windows to a linux apache/php/mysql host. I've sorted out most problems except one. There is an upload...
18
jhardman
by: jhardman | last post by:
Have you ever wanted to upload files through a form and thought, "I'd really like to use ASP, it surely has that capability, but the tutorial I used to learn ASP didn't mention how to do this."? ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.