Load file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to load a file from a dropdownlist, however I get a error saying
a virtual path is required. An example selected value would be
"../4900/myfile.doc". Any ideas - my code is.

Dim sumfin As String = DropDownList1.SelectedValue.ToString
Dim pos As Integer = sumfin.Length
Dim bString As String = sumfin.Substring(3, pos - 3)
Dim cString As String = "http://localhost/" & bString
Server.Transfer(cString)
 
A virtual path would be:

Dim cString As String = "/" & bString

Try that.

Alternately you could go:
Response.Redirect(cString)

P.S.

It's 'something' and not 'sumfin' ;)
 
I have tried response.redirect and the following, which generates "Invalid
path for child request 'c:\inetpub\wwwroot\4900\Framework.doc'. A virtual
path is expected."

Dim sumfin As String = DropDownList1.SelectedValue.ToString
Dim pos As Integer = sumfin.Length
Dim bString As String = Server.MapPath("..\" &
sumfin.Substring(3, pos - 3))
Server.Transfer(bString)

Any other suggestions welcome. Thanks.
 
You won't need the "..\" when you do MapPath(). It takes care of that
for you. The string input would look something like "/Directory/" or
"/Directory/SomeFile.aspx".

Clint Hill
H3O Software
http://www.h3osoftware.com
 
Forget the MapPath

Dim sumfin As String = DropDownList1.SelectedValue.ToString
Dim pos as Integer = sumfin.Legth
Dim bString as String = "/" & sumfin.Substring(3, pos - 3))
Server.Transfer(bString)


or, unless you dead set on Server.Transfer

Dim sumfin As String = DropDownList1.SelectedValue.ToString
Dim pos As Integer = sumfin.Length
Dim bString As String = sumfin.Substring(3, pos - 3)
Dim cString As String = "http://localhost/" & bString
Response.Redirect(cString)
 
I'm curious. Why would you "forget MapPath"?



Grant said:
Forget the MapPath

Dim sumfin As String = DropDownList1.SelectedValue.ToString
Dim pos as Integer = sumfin.Legth
Dim bString as String = "/" & sumfin.Substring(3, pos - 3))
Server.Transfer(bString)


or, unless you dead set on Server.Transfer

Dim sumfin As String = DropDownList1.SelectedValue.ToString
Dim pos As Integer = sumfin.Length
Dim bString As String = sumfin.Substring(3, pos - 3)
Dim cString As String = "http://localhost/" & bString
Response.Redirect(cString)
 
I dunno, being in the virtual directory (http://localhost) i though it
unnecessary
Also, he's redirecting to it, not writing it to screen, so physical path
seemed unnecessary.

Sorry, didn't mean to diss your answer or anything, just trying to simplify
it
 
Have spent a bit of time researching this, server.transfer to a document
just doesn't seem to work, give it up!

However, I do get that error message if I point to the wrong virtual
directory. Are the docs in the same directory as your application or are
they in a folder in the root directory. It works fine for me with
response.redirect. Are you CERTAIN you're redirecting correctly?
 
As requested the html generated by the DDL is below. Using Response.Redirect
I get the following error. Thanks for percevering with this.

System.Threading.ThreadAbortException: Thread was being aborted. at
System.Threading.Thread.AbortInternal() at
System.Threading.Thread.Abort(Object stateInfo) at
System.Web.HttpResponse.End() at System.Web.HttpResponse.Redirect(String url,
Boolean endResponse) at System.Web.HttpResponse.Redirect(String url) at
WebApplication1.WebForm4.DropDownList1_SelectedIndexChanged(Object sender,
EventArgs e) in c:\inetpub\wwwroot\WebApplication1\WebForm4.aspx.vb:line 149

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm4</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<STYLE>
</STYLE>
</HEAD>
<body MS_POSITIONING="GridLayout">
<IFRAME ID=__hifSmartNav NAME=__hifSmartNav STYLE=display:none
src="/aspnet_client/system_web/1_1_4322/SmartNav.htm"></IFRAME>
<form name="Form1" method="post" action="WebForm4.aspx?id=1&Head=Benefits"
id="Form1" __smartNavEnabled="true">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE"
value="dDwtMjEwMzMzOTAyMzt0PDtsPGk8MT47PjtsPHQ8O2w8aTwxPjtpPDM+O2k8Nz47PjtsPHQ8QDA8cDxwPGw8VmlzaWJsZTtQ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XRpb24gLSBDdWx0dXJlLnBwdDsuLi80OTAwL09yZ2FuaXNhdGlvbiAtIEN1bHR1cmUucHB0Oy4uLzQ5MDAvT3JnYW5pc2F0aW9uIC0gU3RydWN0dXJlLnBwdDsuLi80OTAwL2ludHJvZHVjdGlvbi5wZGY7Li4vNDkwMC9GcmFtZXdvcmsuZG9jOy4uLzQ5MDAvY3VsdHVyZS5wZGY7Li4vNDkwMC9Db3Jwb3JhdGUgU3RyYXRlZ3kgTW9kZWxzLnBwdDsuLi80OTAwL09yZ2FuaXNhdGlvbnMg4oCTIFR5cGVzLnBwdDsuLi80OTAwL3N0cnVjdHVyZXMucGRmOy4uLzQ5MDAvc3RydWN0dXJlczIucGRmOy4uLzQ5MDAvVW5pdmVyc2l0eSAyMDA0LnBwdDs+Pjs+Ozs+Oz4+Oz4+Oz6xg6zsT+Iy3AdXLrgBmEm6Zdshhw==" />

<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script>

<script language="JScript"
src="/aspnet_client/system_web/1_1_4322/SmartNav.js"></script>


<center>
<table cellspacing="0" cellpadding="3" align="Center" rules="rows"
bordercolor="#E7E7FF" border="1" id="DataGrid1"
style="background-color:White;border-color:#E7E7FF;border-width:1px;border-style:None;width:672px;border-collapse:collapse;Z-INDEX:
101; LEFT: 8px; POSITION: absolute; TOP: 72px">
<tr style="color:#F7F7F7;background-color:#4A3C8C;font-weight:bold;">
<td>ID</td><td>Heading</td><td>Comments</td><td>Responses</td>
</tr><tr style="color:#4A3C8C;background-color:#E7E7FF;">
<td>1</td><td>When</td><td><a
href="WebForm13.aspx?id=1">Read</a></td><td><a
href="javascript:__doPostBack('DataGrid1$_ctl2$_ctl1','')"
style="color:#4A3C8C;">View</a></td>
</tr><tr style="color:#4A3C8C;background-color:#F7F7F7;">
<td>4</td><td>why</td><td><a
href="WebForm13.aspx?id=4">Read</a></td><td><a
href="javascript:__doPostBack('DataGrid1$_ctl3$_ctl1','')"
style="color:#4A3C8C;">View</a></td>
</tr>
</table></center>
<span id="Label1" style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute;
TOP: 8px">Benefits> </span>
<span id="Label2" style="height:48px;width:128px;Z-INDEX: 104; LEFT:
536px; POSITION: absolute; TOP: 8px">Label</span>
<select name="DropDownList1" onchange="__doPostBack('DropDownList1','')"
language="javascript" id="DropDownList1" style="Z-INDEX: 103; LEFT: 240px;
POSITION: absolute; TOP: 8px">
<option value="../4900/Organisation - Culture.ppt">Organisation -
Culture.ppt</option>
<option value="../4900/Organisation - Culture.ppt">Organisation -
Culture.ppt</option>
<option value="../4900/Organisation - Structure.ppt">Organisation -
Structure.ppt</option>
<option value="../4900/introduction.pdf">introduction.pdf</option>
<option value="../4900/Framework.doc">Framework.doc</option>
<option value="../4900/culture.pdf">culture.pdf</option>
<option value="../4900/Corporate Strategy Models.ppt">Corporate Strategy
Models.ppt</option>
<option value="../4900/Organisations – Types.ppt">Organisations –
Types.ppt</option>
<option value="../4900/structures.pdf">structures.pdf</option>
<option value="../4900/structures2.pdf">structures2.pdf</option>
<option value="../4900/University 2004.ppt">University 2004.ppt</option>

</select></form>
</body>
</HTML>
 
Server.Transfer and Response.Redirect both call Response.End to stop
execution of the current thread. This stops the thread by issuing a
ThreadAbort exception which is a special non-catchable exception (you can
catch it, but can't stop it bubbling up).

Try using Server.Execute instead, or Response.Redirect(url,false).

A simple google will provide plenty of results outlining this (e.g.
http://www.kbalertz.com/kb_312629.aspx)

HTH,
C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top