Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Selector

Status
Not open for further replies.

gslick

Programmer
Sep 9, 2004
18
GB
Hi,

I am trying to create a button that when clicked, opens up a windows for you to select a file on a network. I doesnt have to have the ability to open the file, just select it.
(I would work like the CommonDialogBox would work on VB6)

Has anybody got any code that does this ?

I want it to work with asp.net with vb.net as the langauge

Thanks
 
gs: You should be able to find additional information by doing a serch here, this topic has come upon several occassions. Below I am pasting the code that runs the following page:


It's a simple image upload page; but has the basics.

Code:
<%@ Page Language="VB" Debug="false" %>
<%@Import Namespace = "Microsoft.VisualBasic"%>
<%@Import Namespace = "System"%>
<%@Import Namespace = "System.Web.UI"%>
<%@Import Namespace = "System.Web.UI.WebControls"%>
<%@Import Namespace = "System.Web.UI.HtmlControls"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat=server>

      Dim MyID As String	
      Sub Page_Load(Sender As Object, e As System.EventArgs)
            Session("SDate") = Now()
            ddVantage.Items.Add(New ListItem("?", "01"))
            ddVantage.Items.Add(New ListItem("N", "02"))
            ddVantage.Items.Add(New ListItem("NE", "03"))
            ddVantage.Items.Add(New ListItem("E", "04"))
            ddVantage.Items.Add(New ListItem("SE", "05"))
            ddVantage.Items.Add(New ListItem("S", "06"))
            ddVantage.Items.Add(New ListItem("SW", "07"))
            ddVantage.Items.Add(New ListItem("W", "08"))
            ddVantage.Items.Add(New ListItem("NW", "09"))
          
            lblID.Text = "."         
            MyID = Request.QueryString("AwwSiteCode")
            lblStr.Visible = "True"
            If Len(MyID)>1 Then
              lblID.Text =  MyID 
              lblID.Visible ="True"   
              lblStr.Text = "Your AWW Site Code is:"
              lblStr.Visible ="True"
            End If  
       End Sub                            

       Sub DoUpload(Sender As Object, e As System.EventArgs)
	  Dim sPath as String
          Dim sFile as String
          Dim sFullPath as String
          Dim sSplit() as String
          Dim sPathFriendly as String         
          
          'Upload to same path as script
          'Internet Anonymous User must have write permissions
          
          sPath = Server.MapPath(".\Photos")
          If Right(sPath, 1) <> "\" then 
	    sPathFriendly = sPath 'Friendly path name for display
	    sPath = sPath & "\"
	  Else
	    sPathFriendly = Left(sPath, Len(sPath) - 1)
	  End If			
          
          'Save as same file name being posted
          'The code below resolves the file name
          '(removes path info)
          sFile = txtUpload.PostedFile.FileName
          sSplit = Split(sFile, "\")
          sFile = sSplit(Ubound(sSplit))          
          sFullPath = sPath & sFile
          If PhotoDate.Text = "" Then
            PhotoDate.Text = "01/01/1899"
          End If
	       Try
                  txtUpload.PostedFile.SaveAs(sFullPath)         
                  Catch Ex as Exception			
			lblResults.Text = "Upload of File " & sFile & " to " & sPathFriendly & " failed for the following reason: " & Ex.Message
                  Finally			
	       End Try
                Dim strString As String
                strString = txtMemo.Text
                strString = strSTring.Replace("'","''")
		Dim dbconnNew As OleDbConnection
	        Dim DBCommand As OleDBDataAdapter
                Dim DBInsert As New OleDbCommand
               'Open the database connection
                dbconnNew = New OleDbConnection( _
	        "Provider=Microsoft.Jet.OLEDB.4.0; " & _
	        "Data Source=" & Server.MapPath(".\fpdb\NewData.mdb;"))
                DBInsert.CommandText = "INSERT INTO tblPhotos (Comments, AwwSiteCode, PhotoDate, Vantage) VALUES ('" & strString & "', '" & Me.lblID.Text & "', '" & PhotoDate.Text & "', '" & ddVantage.SelectedItem.Value & "')"
		DBInsert.Connection = dbconnNew
                DBInsert.Connection.Open
                DBInsert.ExecuteNonQuery()
                DBInsert.Connection.Close
		Response.Redirect(".\PhotoConfirm.aspx?AwwSiteCode=" & MyID)
          End Sub
</script>
<HTML>
<Title>AWW Photo Upload Page</Title>
	<body background="images/texturbg.jpg">
        <script language=javascript>
         function GetDate(CtrlName, PHotoDate){   
         ChildWindow = window.open('PhotoCal.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName + '&SDate=' + PHotoDate, "PopUpCalendar", "width=270,height=300,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no");    
        }   
        function CheckWindow(){
          ChildWindow.close(); 
        }
        function Navigate(){
         document.location = "index.aspx";
        }
        </script>
	  <form enctype="multipart/form-data" runat="server" ID="Form1">
	     <P>
		<asp:imagebutton id="imgHydro" runat="server" Width="70px" height="86px" ImageUrl="images\HydroNavy.gif" ImageAlign="Absmiddle"/>
                <FONT face="+1"><B><asp:label id="lblStr" Visible="false" runat="server" Width="170px" ForeColor="Black"/>
                <asp:label id="lblID" Visible="false" runat="server" Width="320px" ForeColor="Red" />
                </B></FONT>
		</P>
		<P>
		<FONT face="+1"><B><font color="#0000ff">Select File To Upload:</font></B></FONT>
		<B><input id="txtUpload" type="file" runat="server" size="20" NAME="txtUpload" ForeColor="red" style="color: #FF0000; font-family: Arial"/>
		</B></P>
                <P><FONT face="+1"><B><font color="#0000ff">Date image was taken: </font></B></FONT>&nbsp;<asp:Textbox id="PhotoDate" runat="server" width="75px"/>
                <a href="javascript:GetDate('PhotoDate','<%=Session("SDate")%>')"><img src="./Images/SmallCalendar.gif" border="0" /></a>
		&nbsp;&nbsp;<FONT face="+1"><B><font color="#0000ff">Image vantage: </font></B></FONT>&nbsp;<asp:dropdownlist id="ddVantage" runat="server" width="46px"/></p>
                <P><asp:TextBox id="txtMemo" runat="server" Width="425px" Height="113px" TextMode="MultiLine" />
		&nbsp;&nbsp;&nbsp;<asp:button id="btnUpload" Font-Bold="true" Text="Upload File" OnClick="DoUpload" runat="server" Width="90px" ForeColor="Blue" />
                &nbsp;&nbsp;<b><Font color="#FF0000"><INPUT TYPE="button" VALUE="Cancel" onClick='javascript:Navigate()' style="color: #FF0000"></Font></b></p>
		<asp:label id="lblResults" Visible="false" runat="server" Width="320px" ForeColor="Red" />
		<asp:RequiredFieldValidator id="rfvMemo" ControlToValidate="txtMemo" runat="server" Display="Dynamic" width="163px" ErrorMessage="A Photo description is Required!" ForeColor="Red" Font-Bold="True" />
	      </form>
		<p align="left"><font size="4"><b><font color="#0000FF">STEP 1.</font></b>&nbsp; 
         
        </font><b>Retrieve your AWW Site Code (<a href="SearchbyCounty.aspx">Click here</a>).<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        If the 
		<rb>image is not of your site, skip this step.</b></p>
		<p align="left"><font size="4" color="#0000FF"><b>STEP 2.</b></font><font size="4">&nbsp; 
         
        </font><b>Locate and load your image using the browse button.</b><p align="left"><font size="4" color="#0000FF"><b>
        STEP 3.&nbsp; </b>
        </font><b>Provide a detailed comment, photo date and vantage for your image.</b></p>
      
	<p align="left"><font size="4" color="#0000FF"><b>STEP 4.&nbsp; </b>
        </font><b>Click on the upload button to submit your image and comments.</b></p>
		<p align="left">&nbsp;&nbsp;&nbsp;&nbsp; You may upload Site 
                photographs, or any other photographs.&nbsp; There is no limit to the 
                number of photographs that you submit, only that they are relevant to 
                water quality issues (AWW Staff will review for clarity and 
                composition).&nbsp; </p>
		<p align="left">&nbsp;&nbsp;&nbsp;&nbsp; If your photograph is not related to your site, 
		please provide us with a Latitude and Longitude, or detailed description of the 
		photograph's location.&nbsp; Also, the photo's vantage point (direction), can be useful 
		if you provide it.&nbsp; The majority of photographs received 
		will end up on AWW's Internet Map Server (IMS), soon to go on line at Auburn 
		University (an electronic map of Alabama very similar to ArcView GIS - if 
		you're interested in more information about the IMS, <u><font color="#0000ff">click 
		here</font></u>).&nbsp;
		</p>
	</body>
</HTML>

...hope this helps
 
gs: The following:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

..is not needed, was residual in the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top