ch gopi

ch gopi

  • NA
  • 2
  • 5.3k

The directory name is invalid.

Nov 17 2017 11:57 PM
This is my code for uploading image onto web page
 
public partial class WebForm8 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("sp_completedprojects", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
var rdr = cmd.ExecuteScalar();
lblcompltedprjts.InnerText = rdr.ToString();
SqlCommand cmd2 = new SqlCommand("sp_inprocessprojects", con);
cmd2.CommandType = CommandType.StoredProcedure;
var rdr2 = cmd2.ExecuteScalar();
lblprjtsundrprcs.InnerText = rdr2.ToString();
SqlCommand cmd3 = new SqlCommand("sp_totalprojects", con);
cmd3.CommandType = CommandType.StoredProcedure;
var rdr3 = cmd3.ExecuteScalar();
lbltotalprjts.InnerText = rdr3.ToString();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/img/home/" + filename));
string file = Directory.GetFiles(Server.MapPath("~/img/home/" + filename)).ToString();
FileInfo fileinfo = new FileInfo(file.ToString());
WebForm4 ctrl = new WebForm4();
Image img = (Image)ctrl.FindControl("img_homebanner");
img.ImageUrl = fileinfo.ToString();
}
}
}
 
i'm getting this exception when i click on button for uploading
 
The directory name is invalid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The directory name is invalid.
Source Error:
Line 49: string filename = FileUpload1.FileName;
Line 50: FileUpload1.PostedFile.SaveAs(Server.MapPath("~/img/home/" + filename));
Line 51: string file = Directory.GetFiles(Server.MapPath("~/img/home/" + filename)).ToString();
Line 52: Line 53: FileInfo fileinfo = new FileInfo(file.ToString());
Source File: C:\Users\Gopi\Documents\Visual Studio 2015\Projects\WebApplication5\Technogen\Dashboard.aspx.cs Line: 51

Answers (1)