On my web page, I have different images of ID card templates that displays in the thumbnail. I want a situation where I can click on an image in the thumbnail it should take that image to another web page for editing, but when I click on an image nothing
happens. I have an error which is confusing to me. The error is in the yellow highlighted line in the ".cs" code page which I have attached to this thread. (Debug.WriteLine(ex.ToString());)
Then when editing, I want to be able to add texts like name and signature; I also want to be able to add something like a passport photograph and a logo on the image that was imported from the previous page in the thumbnail. I do not want to edit or change
the entire imported image but to add those things mentioned above on the image as I'm trying to give users access to make Identity Cards and tickets for printing.
I need assistance on this issues and I will be grateful if these are resolved. Here is the code:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingSystem.Data.SqlClient;publicpartialclassAccure:System.Web.UI.Page{protectedvoidPage_Load(object sender,EventArgs e){string id =Request.QueryString["id"];if(id !=null){if(!IsPostBack){BindDetailsView(id);}}}privatevoidBindDetailsView(string id){string sql ="Select * From blog where Id = @Id";SqlParameter[] parameters =new[]{newSqlParameter("@Id", id)};ImageDetails.DataSource=SelectFromDatabase(sql, parameters);ImageDetails.DataBind();}publicDataTableSelectFromDatabase(string sql,SqlParameter[] parameters){SqlConnection con =newSqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True");{using(SqlCommand cmd =newSqlCommand(sql, con)){if(parameters !=null){
cmd.Parameters.AddRange(parameters);}using(SqlDataAdapter sda =newSqlDataAdapter(cmd)){DataTable dt =newDataTable();
sda.Fill(dt);return dt;}}}}protectedvoidImageDetails_ItemCommand(object sender,DetailsViewCommandEventArgs e){if(e.CommandName.Equals("ChangeImage")){DetailsView dv =(DetailsView)((Button)e.CommandSource).NamingContainer;FileUpload upload =(FileUpload)dv.FindControl("ImageUploader");string id = e.CommandArgument.ToString();if(upload.HasFile){string newPath =SaveFile(upload, upload.PostedFile);//You might need to delete the previous image//Update Image URLstring sql ="Update blog Set card = @card Where Id=@Id";SqlParameter[] parameters =new[]{newSqlParameter("@card", newPath),newSqlParameter("@Id", id)};ExecuteNonQuery(sql, parameters);// Rebind DetailsViewBindDetailsView(id);}}elseif(e.CommandName.Equals("Cancel")){Response.Redirect("RepeaterThumbnail.aspx");}elseif(e.CommandName.Equals("Save")){DetailsView dv =(DetailsView)((Button)e.CommandSource).NamingContainer;string titleText =((TextBox)dv.FindControl("titleTxt")).Text;string contentText =((TextBox)dv.FindControl("contentTxt")).Text;string id = e.CommandArgument.ToString();//Update Image title and contentstring sql ="Update blog Set card_title = @card_title, content = @content Where Id=@Id";SqlParameter[] parameters =new[]{newSqlParameter("@card_title", titleText),newSqlParameter("@content", contentText),newSqlParameter("@Id", id)};ExecuteNonQuery(sql, parameters);Response.Redirect("RepeaterThumbnail.aspx");}}publicintExecuteNonQuery(string sql,SqlParameter[] parameters){// -1 means the query is not successfulint result =-1;SqlConnection conn =newSqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True");{try{
conn.Open();using(SqlCommand cmd =newSqlCommand(sql, conn)){if(null!= parameters){
cmd.Parameters.AddRange(parameters);}
result = cmd.ExecuteNonQuery();}}catch(SqlException ex){Debug.WriteLine(ex.ToString());}finally{
conn.Close();}}return result;}privatestringSaveFile(FileUpload upload,HttpPostedFile file){// Specify the path to save the uploaded file to.string imageFolder ="images/";string savePath =Server.MapPath(imageFolder);// Get the name of the file to upload.string fileName = upload.FileName;// Create the path and file name to check for duplicates.string pathToCheck = savePath + fileName;// Create a temporary file name to use for checking duplicates.string tempfileName ="";// Check to see if a file already exists with the// same name as the file to upload. if(System.IO.File.Exists(pathToCheck)){int counter =2;while(System.IO.File.Exists(pathToCheck)){// if a file with this name already exists,// prefix the filename with a number.
tempfileName = counter.ToString()+ fileName;
pathToCheck = savePath + tempfileName;
counter++;}
fileName = tempfileName;}// Append the name of the file to upload to the path.
savePath += fileName;// Call the SaveAs method to save the uploaded// file to the specified directory.
upload.SaveAs(savePath);return imageFolder + fileName;}}
Ok but how about showing actually the error message you have so that others don't have to read your code and guess which message you SEE ?
Not directly related but your approach is likely counterproductive ie on a production server you won't have a console to show the error message and you don't check the return value. So the error will be basically hidden or you'll see another later error
caused by this hidden errror.
Edit: for now you we know you have an error on the SQL side but it could be absolutely anything from a wrong connection string, to a wrong column name or a string size that is exceeding the allowed length etc etc... It's best to always start from the actual
error message rather than trying to guess.
On my web page, I have different images of ID card templates that displays in the thumbnail. I want a situation where I can click on an image in the thumbnail it should take that image to another web page for editing, but when I click on an image nothing happens
Donald416
Then when editing, I want to be able to add texts like name and signature; I also want to be able to add something like a passport photograph and a logo on the image that was imported from the previous page in the thumbnail. I do not want to edit or change
the entire imported image but to add those things mentioned above on the image as I'm trying to give users access to make Identity Cards and tickets for printing.
The error is in the yellow highlighted line in the ".cs" code page which I have attached to this thread. (Debug.WriteLine(ex.ToString());)
As PatriceSc said, you should post your error message instead of telling us which line of code is wrong.
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
18 Points
98 Posts
Image export
May 02, 2020 08:29 AM|Donald416|LINK
Hello,
On my web page, I have different images of ID card templates that displays in the thumbnail. I want a situation where I can click on an image in the thumbnail it should take that image to another web page for editing, but when I click on an image nothing happens. I have an error which is confusing to me. The error is in the yellow highlighted line in the ".cs" code page which I have attached to this thread. (Debug.WriteLine(ex.ToString());)
Then when editing, I want to be able to add texts like name and signature; I also want to be able to add something like a passport photograph and a logo on the image that was imported from the previous page in the thumbnail. I do not want to edit or change the entire imported image but to add those things mentioned above on the image as I'm trying to give users access to make Identity Cards and tickets for printing.
I need assistance on this issues and I will be grateful if these are resolved. Here is the code:
The Template Page (Template.aspx)
Code behind the Template Page (Template.aspx.cs)
The Edit page(EditPage.aspx)
Code behind the edit page (EditPage.aspx.cs)
Donald Simon
All-Star
48530 Points
18075 Posts
Re: Image export
May 02, 2020 11:05 AM|PatriceSc|LINK
Hi,
Ok but how about showing actually the error message you have so that others don't have to read your code and guess which message you SEE ?
Not directly related but your approach is likely counterproductive ie on a production server you won't have a console to show the error message and you don't check the return value. So the error will be basically hidden or you'll see another later error caused by this hidden errror.
Edit: for now you we know you have an error on the SQL side but it could be absolutely anything from a wrong connection string, to a wrong column name or a string size that is exceeding the allowed length etc etc... It's best to always start from the actual error message rather than trying to guess.
Contributor
3370 Points
1409 Posts
Re: Image export
May 04, 2020 07:32 AM|samwu|LINK
Hi Donal416,
I have answered the same question in this thread.
https://forums.asp.net/t/2166516.aspx
As PatriceSc said, you should post your error message instead of telling us which line of code is wrong.
Best regards,
Sam