when i run this code on local host,its work currect but when upload on server show the error.
code's :
if (fUploadImg.HasFile)
{
try
{
if (System.IO.File.Exists(Server.MapPath("../Article/" + fUploadImg.FileName)))
{
ErrorMessage.Text = "exist file";
fImgName = fUploadImg.FileName;
}
else
{
fUploadImg.SaveAs(Server.MapPath("../Article/" + fUploadImg.FileName));
fImgName = fUploadImg.PostedFile.FileName;
}
}
catch (Exception err)
{
ErrorMessage.Text = "error " + err.Message;
}
finally
{
}
}
else
{
fImgName = "Article.png";
}
SqlConnection con = new SqlConnection(cData.constr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = string.Format("INSERT INTO tblArticle(aTitle,aText,aImg,aUrl,aDate,aDownlodable,aNote)VALUES(@title,@text,@imgN,@atachFn,@date,@down,@note)");
cmd.Parameters.AddWithValue("@title", txtArticleTitle.Text.Trim());
cmd.Parameters.AddWithValue("@text", CKEditor1.Text);
cmd.Parameters.AddWithValue("@imgN", fImgName);
cmd.Parameters.AddWithValue("@atachFn", fAtachName);
cmd.Parameters.AddWithValue("@note", txtNote.Text);
cmd.Parameters.AddWithValue("@date", date);
cmd.Parameters.AddWithValue("@down", rdoDownloadable.SelectedValue);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
clearObject();
error : Server Error in '/' Application.
The parameterized query '(@title nvarchar(3),@text nvarchar(3),@imgN nvarchar(4000),@atac
' expects the parameter '@imgN
', which was not supplied.
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.Data.SqlClient.SqlException
: The parameterized query '(@title nvarchar(3),@text nvarchar(3),@imgN nvarchar(4000),@atac
' expects the parameter '@imgN
', which was not supplied.
Source Error:
Line 133:
Line 134: con.Open();
Line 135: cmd.ExecuteNonQuery();
Line 136: con.Close();
Line 137: clearObject();
please help quickly.
thanks.
Change the ..
to ~
in your codes to specify the root of the site.
var folder = Server.MapPath("~/Article");
Then contact your hosting provider and tell them your program needs a write access
to the Article
folders. It's not set by default.