I created a site where I issue PDF or JPEG documents files to clients with a QR code on the documents. The issue I am facing is that when the QR code is scanned it displays a link with the document ID and when I navigate to the link it shows this:
Your file couldn't be accessed It may have been moved, edited, or deleted. ERR_FILE_NOT_FOUND
But the file is inside the httpdocs folder in my Plesk. How do I resolve this?
Here is the link it displays on a QR code scanner G:\PleskVhosts\docissuers.com\httpdocs\UIdoc.aspx?Id=3
here is the code used to generate the QR code
C#
private string imgBytes;
private object Inv;
protected void Page_Load(object sender, EventArgs e)
{
BindCardAndQR();
}
private void BindCardAndQR()
{
if (Session["paperinv"] != null)
{
int id = Convert.ToInt32(Session["paperinv"]);
string sql = "SELECT * FROM tableinvoice WHERE Id = @Id";
SqlParameter[] parameters = new[] {
new SqlParameter("@Id", id)
};
// Bind Image3 for Card Image
DataTable dt = SelectFromDatabase(sql, parameters);
if (dt.Rows.Count > 0)
{
string embed = "<object data=\"{0}{1}\" type=\"application/pdf\"></object>";
ltEmbed.Text = string.Format(embed, ResolveUrl("Handler.ashx?Id="), id);
byte[] QRBytes = GetQRCodeBytes(Server.MapPath("~/IUdoc.aspx") + "?Id=" + id);
Image1.ImageUrl = "data:image/jpg;base64," + Convert.ToBase64String(QRBytes);
}
}
}
public byte[] GetQRCodeBytes(string url)
{
//QR code generated here
QRCodeEncoder encoder = new QRCodeEncoder();
Bitmap bi = encoder.Encode(url);
MemoryStream tmpSteam = new MemoryStream();
bi.Save(tmpSteam, ImageFormat.Jpeg);
return tmpSteam.ToArray();
}
public static DataTable SelectFromDatabase(string sql, SqlParameter[] parameters)
{
using (SqlConnection con = new SqlConnection("myconstring"))
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (parameters != null)
{
cmd.Parameters.AddRange(parameters);
}
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}