5 Replies - 1525 Views - Last Post: 23 October 2009 - 06:48 PM Rate Topic: -----

#1 Pablo3728  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 13-October 09

Show my files in other url

Post icon  Posted 22 October 2009 - 08:52 AM

Hi! Well, I have an ASP.NET WEb Application in vb.net. THe application has a fileupload and an Upload button that works ok, but now, I want to show my file in other url using Response.Redirect("url").
My problem is the next, when I put the instruccion : Response.Redirect("url") in the upload button, my program works ok, but I want to put the instruccion in a LinkButton, but when i put the instruccion in these place my program can´t find the page.

THis is my code:

 <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="AplicacionWebPablo._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

	Protected Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

		' Specify the path on the server to
		' save the uploaded file to.
		Dim savePath As String = "c:\inetpub\wwwroot\pablo\"

		' Before attempting to save the file, verify
		' that the FileUpload control contains a file.
		If (FileUpload1.HasFile) Then

			' Get the size in bytes of the file to upload.
			Dim fileSize As Integer = FileUpload1.PostedFile.ContentLength

			' Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded.
			If (fileSize < 2100000) Then

				' Append the name of the uploaded file to the path.
				savePath += Server.HtmlEncode(FileUpload1.FileName)

				' Call the SaveAs method to save the 
				' uploaded file to the specified path.
				' This example does not perform all
				' the necessary error checking.			   
				' If a file with the same name
				' already exists in the specified path,  
				' the uploaded file overwrites it.
				FileUpload1.SaveAs(savePath)

				' Notify the user that the file was uploaded successfully.
				UploadStatusLabel.Text = "Su archivo se ha subido correctamente"

			Else
				' Notify the user why their file was not uploaded.
				UploadStatusLabel.Text = "Su archivo no se ha podido subir, debido a que excede " + _
										 "el límite de memoria (2MB)."
			End If

		Else
			' Notify the user that a file was not uploaded.
			UploadStatusLabel.Text = "No ha especificado el archivo a subir."
		End If
		LinkButton1.Text = "http://desarrollo1/pablo/" & FileUpload1.FileName
		
		'Response.Redirect("http://desarrollo1/pablo/" & FileUpload1.FileName)
	End Sub
	
 
	
</script>

<script runat="server">
	Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
		Response.Redirect("http://desarrollo1/pablo/" & FileUpload1.FileName)
	End Sub
</script>



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
	<title>Ejemplo de subir archivos</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
	<h4>
		 Seleccione el archivo a subir:</h4>

	   <asp:FileUpload id="FileUpload1"				 
		   runat="server">
	   </asp:FileUpload>

	   <br/><br/>

	   <asp:Button id="UploadButton" 
		   Text="Subir Archivo"
		   onclick="UploadButton_Click"
		   runat="server">
	   </asp:Button>
	 
	   <hr />

	   <asp:Label id="UploadStatusLabel"
		   runat="server">
	   </asp:Label><br />
		<br />
		<asp:LinkButton ID="LinkButton1" onclick="LinkButton1_Click" runat="server"></asp:LinkButton><br />
		<br />
		<asp:Button ID="Button1" runat="server" Text="Button" /></div>
	</form>
</body>
</html> 



THank you!!! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Show my files in other url

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Show my files in other url

Posted 22 October 2009 - 04:40 PM

The Text property of a LinkButton is what is displayed on the client computer. You also need to set the PostBackUrl property with the URL to where you want the user redirected to.

LinkButton1.Text = "http://desarrollo1/pablo/" & FileUpload1.FileName
LinkButton1.PostBackUrl = "http://desarrollo1/pablo/" & FileUpload1.FileName


Was This Post Helpful? 0
  • +
  • -

#3 Pablo3728  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 13-October 09

Re: Show my files in other url

Posted 23 October 2009 - 06:23 AM

THank you Jayman! Well I put this line, but happen the same, the program can´t fine the page.
If I put the line Response.Redirect("http://desarrollo1/pablo/" & FileUpload1.FileName) in the Uploadbutton the program works ok, but If put in the event click of my buttonLink the program doesn´t work.

 <script runat="server">
	Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
		LinkButton1.PostBackUrl = "http://desarrollo1/pablo/" & FileUpload1.FileName
		Response.Redirect("http://desarrollo1/pablo/" & FileUpload1.FileName)
	End Sub
</script> 


The complete code:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="AplicacionWebPablo._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

	Protected Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

		' Specify the path on the server to
		' save the uploaded file to.
		Dim savePath As String = "c:\inetpub\wwwroot\pablo\"

		' Before attempting to save the file, verify
		' that the FileUpload control contains a file.
		If (FileUpload1.HasFile) Then

			' Get the size in bytes of the file to upload.
			Dim fileSize As Integer = FileUpload1.PostedFile.ContentLength

			' Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded.
			If (fileSize < 2100000) Then

				' Append the name of the uploaded file to the path.
				savePath += Server.HtmlEncode(FileUpload1.FileName)

				' Call the SaveAs method to save the 
				' uploaded file to the specified path.
				' This example does not perform all
				' the necessary error checking.			   
				' If a file with the same name
				' already exists in the specified path,  
				' the uploaded file overwrites it.
				FileUpload1.SaveAs(savePath)

				' Notify the user that the file was uploaded successfully.
				UploadStatusLabel.Text = "Su archivo se ha subido correctamente"

			Else
				' Notify the user why their file was not uploaded.
				UploadStatusLabel.Text = "Su archivo no se ha podido subir, debido a que excede " + _
										 "el límite de memoria (2MB)."
			End If

		Else
			' Notify the user that a file was not uploaded.
			UploadStatusLabel.Text = "No ha especificado el archivo a subir."
		End If
		LinkButton1.Text = "http://desarrollo1/pablo/" & FileUpload1.FileName
		LinkButton1.PostBackUrl = "http://desarrollo1/pablo/" & FileUpload1.FileName
		
		'Response.Redirect("http://desarrollo1/pablo/" & FileUpload1.FileName)
	End Sub
  
	
</script>

<script runat="server">
	Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
		LinkButton1.PostBackUrl = "http://desarrollo1/pablo/" & FileUpload1.FileName
		Response.Redirect("http://desarrollo1/pablo/" & FileUpload1.FileName)
	End Sub
</script>



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
	<title>Ejemplo de subir archivos</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
	<h4>
		 Seleccione el archivo a subir:</h4>

	   <asp:FileUpload id="FileUpload1"				 
		   runat="server">
	   </asp:FileUpload>

	   <br/><br/>

	   <asp:Button id="UploadButton" 
		   Text="Subir Archivo"
		   onclick="UploadButton_Click"
		   runat="server">
	   </asp:Button>
	 
	   <hr />

	   <asp:Label id="UploadStatusLabel"
		   runat="server">
	   </asp:Label><br />
		<br />
		<asp:LinkButton ID="LinkButton1" onclick="LinkButton1_Click" runat="server"></asp:LinkButton><br />
		<br />
		</div>
	</form>
</body>
</html>


I really don´t know what happen...
Thank you for your help! :)

Pablo

This post has been edited by Pablo3728: 23 October 2009 - 07:23 AM

Was This Post Helpful? 0
  • +
  • -

#4 Pablo3728  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 13-October 09

Re: Show my files in other url

Post icon  Posted 23 October 2009 - 07:47 AM

Hi! Well, I have an ASP.NET WEb Application in vb.net. THe application has a fileupload and an Upload button that works ok, but now, I want to show my file in other url using a linkbutton.
My problem is the next, when I put the instruccion : Response.Redirect("url") in the upload button, my program works ok, but I want to put the instruccion in the LinkButton, but when i put the instruccion in these place my program can´t find the page.

this is the code from my link button
 Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
		LinkButton1.PostBackUrl = ("http://desarrollo1/pablo/" & FileUpload1.FileName)
		Response.Redirect("http://desarrollo1/pablo/" & FileUpload1.FileName)
	End Sub 


THe code of the upload button is

<script runat="server">

	Protected Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

		' Specify the path on the server to
		' save the uploaded file to.
		Dim savePath As String = "c:\inetpub\wwwroot\pablo\"

		' Before attempting to save the file, verify
		' that the FileUpload control contains a file.
		If (FileUpload1.HasFile) Then
			

			' Get the size in bytes of the file to upload.
			Dim fileSize As Integer = FileUpload1.PostedFile.ContentLength

			' Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded.
			If (fileSize < 2100000) Then

				' Append the name of the uploaded file to the path.
				savePath += Server.HtmlEncode(FileUpload1.FileName)

				' Call the SaveAs method to save the 
				' uploaded file to the specified path.
				' This example does not perform all
				' the necessary error checking.			   
				' If a file with the same name
				' already exists in the specified path,  
				' the uploaded file overwrites it.
				FileUpload1.SaveAs(savePath)
				' Notify the user that the file was uploaded successfully.
				UploadStatusLabel.Text = "Su archivo se ha subido correctamente"

			Else
				' Notify the user why their file was not uploaded.
				UploadStatusLabel.Text = "Su archivo no se ha podido subir, debido a que excede " + _
										 "el límite de memoria (2MB)."
			End If

		Else
			' Notify the user that a file was not uploaded.
			UploadStatusLabel.Text = "No ha especificado el archivo a subir."
		End If
		LinkButton1.Text = "http://desarrollo1/pablo/" & FileUpload1.FileName
	End Sub
   
</script> 


And the rest for some duve:

 <html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
	<title>Ejemplo de subir archivos</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
	<h4>
		 Seleccione el archivo a subir:</h4>

	   <asp:FileUpload id="FileUpload1"				 
		   runat="server">
	   </asp:FileUpload>

	   <br/><br/>

	   <asp:Button id="UploadButton" 
		   Text="Subir Archivo"
		   onclick="UploadButton_Click"
		   runat="server">
	   </asp:Button>
	 
	   <hr />
	   <asp:Label id="UploadStatusLabel"
		   runat="server">
	   </asp:Label><br />
		<br />
		<asp:LinkButton ID="LinkButton1" onclick="LinkButton1_Click"  runat="server"></asp:LinkButton><br />
		<br />
		&nbsp;</div>
	</form>
</body>
</html>


If somebody could help me would be great!
Thank you! :)
Pablo
Was This Post Helpful? 0
  • +
  • -

#5 Pablo3728  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 13-October 09

Re: Show my files in other url

Posted 23 October 2009 - 08:34 AM

I could resolved! Instead to use one LinkButton I used one HyperLink, and the next code in the event click of uploadbutton:

 HyperLink1.Text = "http://desarrollo1/pablo/" & FileUpload1.FileName
		HyperLink1.NavigateUrl = "http://desarrollo1/pablo/" & FileUpload1.FileName


I put the solution of this problem, becouse somebody may has the same problem :)
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Show my files in other url

Posted 23 October 2009 - 06:48 PM

Removing the following code will solve the problem. If you set the PostBackUrl you don't need to use the Click event.

<script runat="server">
	Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
		LinkButton1.PostBackUrl = "http://desarrollo1/pablo/" & FileUpload1.FileName
		Response.Redirect("http://desarrollo1/pablo/" & FileUpload1.FileName)
	End Sub
</script>




Topics merged. Please do not create duplicate topics in the future.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1