|
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 that it'll fire when the winform
tries to upload a file? (It seems that the page load event might be ok, but,
is the page ever loaded?)
I don't want the Winform user to ever see the upload.aspx page. I just want
the Winform UploadFile command to use the form to put the file on the
server.
Any help would be greatly appreciated!!
|
|
|
|