Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Winform UploadFile to Upload.aspx page (VB.Net 2005)

Winform UploadFile to Upload.aspx page (VB.Net 2005)

Scheduled Pinned Locked Moved Visual Basic
sysadminquestioncsharphtml
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    S Dhanasekaran
    wrote on last edited by
    #1

    Hi All, I need some help with customizing an upload.aspx. I have a VB.Net 2005 Winform that has a file picker and a textbox (plus loads of other stuff). When the user selects a file, I want to upload the file to a server. This is the command I am using in my Winform to upload the file: My.Computer.Network.UploadFile(CStr(e.Value), Files_Dir, "user", "password", True, 100, FileIO.UICancelOption.ThrowException) Where Files_dir = http://server/upload.aspx Separately, I've created an upload.aspx page that works fine. When I select a file or type a filename into the textbox on the upload.aspx page and click upload, the file is uploaded to the correct directory on the server. The upload.aspx form is simple with just one textbox and 2 buttons: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition al.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Upload</title> </head> <body> <form id="frmUp" runat="server"> <div> <input id="inpFile" type="file" runat="server" /><br/> <asp:Button id="btn_Upload" runat="server" text="Upload" /><br /> <span id="txtMsg" runat="server" /> </div> </form> </body> </html> And the code behind: Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Upload.Click Dim i As Integer Dim objFile As HttpPostedFile Dim strFileName As String Dim strMessage As String = "" For i = 0 To Request.Files.Count - 1 objFile = Request.Files(i) If Len(objFile.FileName) > 0 Then strFileName objFile.FileName.Substring(objFile.FileName.LastInd exOf("\") + 1) Try objFile.SaveAs(Server.MapPath("~/Files") & "/" & strFileName) strMessage &= "<span>" & strFileName & " successfully uploaded</span><br/>" Catch ex As Exception strMessage &= "<span>Failed uploading " & strFileName & ": " & ex.ToString() & "</span><br/>" End Try End If Next i txtMsg.InnerHtml = strMessage End Sub So, how do I pass the filename to be uploaded to the upload.aspx page? (Something like http://server/upload.aspx?filename)??? I know the code that's in the button click event will work when someone actually clicks the button, but where do I put the code so

    C 1 Reply Last reply
    0
    • S S Dhanasekaran

      Hi All, I need some help with customizing an upload.aspx. I have a VB.Net 2005 Winform that has a file picker and a textbox (plus loads of other stuff). When the user selects a file, I want to upload the file to a server. This is the command I am using in my Winform to upload the file: My.Computer.Network.UploadFile(CStr(e.Value), Files_Dir, "user", "password", True, 100, FileIO.UICancelOption.ThrowException) Where Files_dir = http://server/upload.aspx Separately, I've created an upload.aspx page that works fine. When I select a file or type a filename into the textbox on the upload.aspx page and click upload, the file is uploaded to the correct directory on the server. The upload.aspx form is simple with just one textbox and 2 buttons: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition al.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Upload</title> </head> <body> <form id="frmUp" runat="server"> <div> <input id="inpFile" type="file" runat="server" /><br/> <asp:Button id="btn_Upload" runat="server" text="Upload" /><br /> <span id="txtMsg" runat="server" /> </div> </form> </body> </html> And the code behind: Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Upload.Click Dim i As Integer Dim objFile As HttpPostedFile Dim strFileName As String Dim strMessage As String = "" For i = 0 To Request.Files.Count - 1 objFile = Request.Files(i) If Len(objFile.FileName) > 0 Then strFileName objFile.FileName.Substring(objFile.FileName.LastInd exOf("\") + 1) Try objFile.SaveAs(Server.MapPath("~/Files") & "/" & strFileName) strMessage &= "<span>" & strFileName & " successfully uploaded</span><br/>" Catch ex As Exception strMessage &= "<span>Failed uploading " & strFileName & ": " & ex.ToString() & "</span><br/>" End Try End If Next i txtMsg.InnerHtml = strMessage End Sub So, how do I pass the filename to be uploaded to the upload.aspx page? (Something like http://server/upload.aspx?filename)??? I know the code that's in the button click event will work when someone actually clicks the button, but where do I put the code so

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Write a webservice instead of mucking around with this. It can run on the same site as your webpage, so the files will be on the server with your website.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups