Querystring , Quando non c'è che fare...

martedì 07 luglio 2009 - 18.06

Anonimo Profilo | Senior Member

salve, ho questo codice , che funziona se gli passo il parametro e il file , però se non c'è niente mi da errore,
come posso fare quando il parametro è sbagliato o non esista il file mi da un messaggio tipo "Non c'è niente",
ecco il codice:
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data.Odbc; using System.Data; using System.IO; public partial class page_read : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) popola(); } private void popola() { string Page = "" + Request.QueryString["Page"] + ""; StreamReader sr = new StreamReader("d:/wwwroot/www/public/pagine/" + Page + ""); while (!sr.EndOfStream) { vipage.InnerHtml += sr.ReadLine().ToString() + '\r' + '\n'; } sr.Close(); } }

risolto con questo:
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data.Odbc; using System.Data; using System.IO; public partial class page_read : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) popola(); } private void popola() { if (Request.QueryString["Page"] != null) { StreamReader sr = new StreamReader("d:/wwwroot/www/public/pagine/" + Page + ""); while (!sr.EndOfStream) { vipage.InnerHtml += sr.ReadLine().ToString() + '\r' + '\n'; } sr.Close(); } else { vipage.InnerHtml = "Non c'è niente"; } } }

Dampyr Profilo | Junior Member

Un modo è questo:
If Request.QueryString.AllKeys.Contains("tua_chiave") Then Else End If


... cerca di essere il giocatore di scacchi, non il pezzo sulla scacchiera...
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5