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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Newbie Question

Status
Not open for further replies.

Woolers

Technical User
Jan 11, 2005
56
0
0
GB
Hi All,

I'm very new to all this .NET but am good with vb script.
Anyway, I'm trying to get round the 2GB Limit of uploading & so have cobbled together a get around script that will be used internally (with the help of googling for the right scripts..

I have a webpage (default.aspx) that has an upload button on it - the code behind the aspx.vb is as follows:


Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ob, s, objshell, objfolder, parentfolder, fso
Const oProgressBox = &H0&
ob = New FindFile
s = ob.Browse

parentfolder = "\\servername\c$"
objshell = CreateObject("Shell.Application")
objfolder = objshell.NameSpace(parentfolder)
objfolder.CopyHere(s, oProgressBox)

ob = Nothing



'-----------------BEGIN CLASS BLOCK -----------------------------------
'-- Use: Set obj = New FindFile
'-- var = obj.Browse
'-------------- var is path of file selected. -----------------------------
'---------------------------------------------------------------------
End Sub
Class FindFile
Private fso, sPath1

'--FileSystemObject needed to check file path:

Private Sub Class_Initialize()
fso = CreateObject("Scripting.FileSystemObject")
End Sub

'---------------release FSO when class is released:

Private Sub Class_Terminate()
fso = Nothing
End Sub

'--The public one function in this class:

Public Function Browse()
On Error Resume Next
sPath1 = GetPath()
Browse = sPath1
End Function

Private Function GetPath()
Dim Ftemp, ts, IE, sPath, wscript

'-----------Get the TEMP folder path and create a text file in it:
Ftemp = fso.GetSpecialFolder(2)
Ftemp = Ftemp & "\FileBrowser.html"
ts = fso.CreateTextFile(Ftemp, True)

'----------------------write the webpage needed for file browsing window:

ts.WriteLine("<HTML><HEAD><TITLE></TITLE></HEAD>")
ts.WriteLine("<BODY BGCOLOR=" & Chr(34) & "#F3F3F8" & Chr(34) & " TEXT=" & Chr(34) & "black" & Chr(34) & ">")
ts.WriteLine("<script language=" & Chr(34) & "VBScript" & Chr(34) & ">")

'--------when OK is clicked assign path to statustext property:
ts.WriteLine("sub but_onclick()")
ts.WriteLine("status = document.forms(0).elements(0).value")
ts.WriteLine("end sub")

'--------when CANCEL is clicked assign "cancel" to statustext property:
ts.WriteLine("sub butc_onclick()")
ts.WriteLine("status = " & Chr(34) & "cancel" & Chr(34))
ts.WriteLine("end sub")
ts.WriteLine("</script>")

ts.WriteLine("<DIV ALIGN=" & Chr(34) & "center" & Chr(34) & ">")
ts.WriteLine("<FONT FACE=" & Chr(34) & "arial" & Chr(34) & " SIZE=2>")
ts.WriteLine("<BR>")
ts.WriteLine("<FORM>")

'-----------this is the file browsing box in webpage:
ts.WriteLine("<INPUT TYPE=" & Chr(34) & "file" & Chr(34) & "></input>")

'-----------this is the OK button:
ts.WriteLine("<input type=" & Chr(34) & "button" & Chr(34) & " id=" & Chr(34) & "but" & Chr(34) & " value=" & Chr(34) & "OK" & Chr(34) & "></input>")
ts.WriteLine("<BR><BR>")
'------------this is the CANCEL button:
ts.WriteLine("<input type=" & Chr(34) & "button" & Chr(34) & " id=" & Chr(34) & "butc" & Chr(34) & " value=" & Chr(34) & "CANCEL" & Chr(34) & "></input>")
ts.WriteLine("<BR><BR> Browse for file, then click OK.")
ts.WriteLine("</FORM>")
ts.WriteLine("</FONT></DIV>")
ts.WriteLine("</BODY></HTML>")
ts.Close()
ts = Nothing
On Error Resume Next

'--webpage is written. now have IE open it:

IE = wscript.CreateObject("InternetExplorer.Application")
IE.Navigate("file:///" & Ftemp)
IE.AddressBar = False
IE.menubar = False
IE.ToolBar = False
IE.width = 400
IE.height = 250
IE.resizable = False
IE.visible = True

'--do a loop every 1/2 second until either:
'-- the browsing window value is a valid file path or
'-- CANCEL is clicked (setting IE.StatusText to "cancel") or
'--IE is closed from the control box.

Do While IE.visible = True
sPath = IE.StatusText '--------get statustext value.
If fso.FileExists(sPath) = True Or sPath = "cancel" Or IE.visible = False Then
Exit Do
End If
wscript.sleep(500)
Loop
IE.visible = False
IE.Quit()
IE = Nothing
If fso.FileExists(sPath) = True Then
GetPath = sPath
Else
GetPath = ""
End If
End Function
End Class


End Class

When I run it I get the following error:

Exception Details: System.NullReferenceException: Object variable or With block variable not set.

Source Error:


Line 12: objshell = CreateObject("Shell.Application")
Line 13: objfolder = objshell.NameSpace(parentfolder)
Line 14: objfolder.CopyHere(s, oProgressBox)
Line 15:
Line 16: ob = Nothing


Is this something someone is able to help with? I'd love to get this working!

Thanks

Keyboard Not Detected.....
Press F1 to Continue.
:}
 
Oh, it's line 14 causing the problem..

Keyboard Not Detected.....
Press F1 to Continue.
:}
 
Anyone ???

Keyboard Not Detected.....
Press F1 to Continue.
:}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top