Alex E.
asked on
VBSCRIPT in Page Load C# ASP.NET
I have this VBscript code in the head section of an asp.net c# form for a webapp:
How can we do to execute that in the page load of asp.net c# code behind?
Because if you run the page never redirect to inactive.aspx
Thank you
<script language="vbscript" type="text/vbscript">
Dim myString, valuecn, cn, stringvalue
valuecn = Request.QueryString("valuecn")
if valuecn = "" then valuecn = "inactivo" End If
If valuecn = "inactive" then
Response.Redirect("inactive.aspx")
End if
</script>
How can we do to execute that in the page load of asp.net c# code behind?
Because if you run the page never redirect to inactive.aspx
Thank you
ASKER
Yes "inactivo" was a bad typo. But I asked because in this code in regular asp working but when we passed together with the routine I posted in the beginning the next part of code is presenting some troubles:
The errors show the script are:
The "Response.CodePage = 65001" gives me this error: 'FileExists' is not a member of 'String'.
The size = objfile.size shows this 'size' is not a member of 'String'.
The fname = objfile.name shows this 'size' is not a member of 'String'.
'The objStream = Server.CreateObject("ADODB .Stream") shows objStream' is not declared. It may be inaccessible due to its protection level.
This script what it does is if you call for example dwnloadfile.asp?path=anypa th what it does is download the file without executing in browser.
For example in that parts what are the problems? with normal asp you just enter <% %> in the middle code and that´s it but that routine we can´t convert to VB in asp.net.
Imports System.Data
Imports System.IO
Partial Class launch_file2
Inherits System.Web.UI.Page
Dim size As Integer
Dim snfile As String
Dim fs As String
Dim objfile As String
Dim mime_type As String
Dim fname As String
Dim GetFile As String
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Response.CodePage = 65001
Response.Charset = "utf-8"
snfile = Request.QueryString("path")
fs = Server.CreateObject("scripting.filesystemobject")
If fs.FileExists(Server.MapPath(snfile)) = True Then
objfile = fs.GetFile(Server.MapPath(snfile))
size = objfile.size
fname = objfile.name
mime_type = "application/save-as"
Response.AddHeader("Expires:", 0)
Response.ContentType = mime_type
Response.AddHeader("Content-Disposition", "attachment; filename=" & fname)
objStream = Server.CreateObject("ADODB.Stream")
objStream.Open()
objStream.Type = 1
objStream.LoadFromFile(Server.MapPath(snfile))
Response.BinaryWrite(objStream.Read)
Else
Response.Write("File not found!")
Response.End()
End If
End Sub
The errors show the script are:
The "Response.CodePage = 65001" gives me this error: 'FileExists' is not a member of 'String'.
The size = objfile.size shows this 'size' is not a member of 'String'.
The fname = objfile.name shows this 'size' is not a member of 'String'.
'The objStream = Server.CreateObject("ADODB
This script what it does is if you call for example dwnloadfile.asp?path=anypa
For example in that parts what are the problems? with normal asp you just enter <% %> in the middle code and that´s it but that routine we can´t convert to VB in asp.net.
so just to confirm...
1. are you intend to do above in C# and not vb.net ?
2. or you just want to solve the error above in vb.net?
1. are you intend to do above in C# and not vb.net ?
2. or you just want to solve the error above in vb.net?
ASKER
Just convert that one to vb.net
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
Open in new window
pls aware of line:Open in new window
i'm not too sure if inactivo was a typo? should it be inactive instead?