Salve, mi dite come faccio ad controllare se esiste il file ?
questo è 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 basePath = "";
string myPath = Request.QueryString["page"];
string filePath = string.Concat(basePath, myPath);
if (!String.IsNullOrEmpty(filePath))
{
if (myPath.IndexOfAny(Path.GetInvalidFileNameChars()) > -1)
throw new FileNotFoundException("FileName not valid");
if (!filePath.StartsWith(basePath))
throw new FileNotFoundException("Path not valid");
StreamReader sr = new StreamReader(Server.MapPath("/public/pagine/") + filePath + "");
while (!sr.EndOfStream)
{
vipage.InnerHtml += sr.ReadLine().ToString() + '\r' + '\n';
}
sr.Close();
}
else
{
vipage.InnerHtml = "Non c'è niente";
}
}
}
quando faccio cosi page_read.aspx?page=d
essendo d non è un file mi da errore qua:
Errore server nell'applicazione '/'.
Impossibile trovare il file 'D:\wwwroot\www\public\pagine\d'.
Descrizione: Eccezione non gestita durante l'esecuzione della richiesta Web corrente. Per ulteriori informazioni sull'errore e sul suo punto di origine nel codice, vedere l'analisi dello stack.
Dettagli eccezione: System.IO.FileNotFoundException: Impossibile trovare il file 'D:\wwwroot\www\public\pagine\d'.
Errore nel codice sorgente:
Riga 36: if (!filePath.StartsWith(basePath))
Riga 37: throw new FileNotFoundException("Path not valid");
Riga 38: StreamReader sr = new StreamReader(Server.MapPath("/public/pagine/") + filePath + "");
Riga 39: while (!sr.EndOfStream)
Riga 40: {
Mi dite come fare?.
grazie mille.