Brian
asked on
FileUpload only PDF Files
Hello EE,
I have a scenario that is driving me crazy. I have the following code below that ONLY allows a user to upload .pdf files which is what I need. BUT, if the user does not select a file to upload then the code does not execute and instead the page postback to itself.
I tested my SP and they all seem fine, the problem has to do with my code not allowing updates unless I select a file to upload. If i only update the txtPhysicalDateCompleted Control then the page Postback to itself.
protected void btn_SaveAnnualPhysical_Cli ck(object sender, EventArgs e)
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post edFile == null || string.IsNullOrEmpty(fuAnn ualPhysica lForm.Post edFile.Fil eName) || fuAnnualPhysicalForm.Poste dFile.Inpu tStream == null)
{
}
//Make sure we are dealing a .pdf file only
string extension = Path.GetExtension(fuAnnual PhysicalFo rm.PostedF ile.FileNa me).ToLowe r();
string MIMEType = null;
switch (extension)
{
case ".pdf":
MIMEType = "application/pdf";
break;
default:
//Invalid file type Error Message
lblUploadTypeError.Text = "Only .pdf files are allowed";
return;
}
//string MIMEType = fuAnnualPhysicalForm.Poste dFile.Cont entType;
string filename = fuAnnualPhysicalForm.Poste dFile.File Name.Split (new char[] { '\\' }).Last();
int fileSize = fuAnnualPhysicalForm.Poste dFile.Cont entLength;
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu alPhysical ";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm. PostedFile .InputStre am.Length + 1];
fuAnnualPhysicalForm.Poste dFile.Inpu tStream.Re ad(imageBy tes, 0, imageBytes.Length);
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValu e("@ap_pdf _file", SqlDbType.Image).Value = imageBytes;
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = MIMEType;
cmd.Parameters.AddWithValu e("@ap_pdf _size", SqlDbType.VarChar).Value = fileSize;
cmd.Parameters.AddWithValu e("@ap_sec tion_compl ete", SqlDbType.Int).Value = cb_AnnualPhysical.Checked;
if (string.IsNullOrEmpty(txtP hysicalDat eCompleted .Text))
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = DBNull.Value;
}
else
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = txtPhysicalDateCompleted.T ext;
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP hysical_Su ccess.aspx ");
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
I have a scenario that is driving me crazy. I have the following code below that ONLY allows a user to upload .pdf files which is what I need. BUT, if the user does not select a file to upload then the code does not execute and instead the page postback to itself.
I tested my SP and they all seem fine, the problem has to do with my code not allowing updates unless I select a file to upload. If i only update the txtPhysicalDateCompleted Control then the page Postback to itself.
protected void btn_SaveAnnualPhysical_Cli
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post
{
}
//Make sure we are dealing a .pdf file only
string extension = Path.GetExtension(fuAnnual
string MIMEType = null;
switch (extension)
{
case ".pdf":
MIMEType = "application/pdf";
break;
default:
//Invalid file type Error Message
lblUploadTypeError.Text = "Only .pdf files are allowed";
return;
}
//string MIMEType = fuAnnualPhysicalForm.Poste
string filename = fuAnnualPhysicalForm.Poste
int fileSize = fuAnnualPhysicalForm.Poste
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm.
fuAnnualPhysicalForm.Poste
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
if (string.IsNullOrEmpty(txtP
{
cmd.Parameters.AddWithValu
}
else
{
cmd.Parameters.AddWithValu
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
Are you using the ASP.NET FileUpload control, or are you using a 3rd party upload control?
ASKER
ASP.NET FileUpload Control.
Wrap your code in an "if" check:
protected void btn_SaveAnnualPhysical_Click(object sender, EventArgs e)
{
if (fuAnnualPhysicalForm.HasFile)
{
// your other code here
}
}
ASKER
Ok, I wrapped my code as you requested and I have no problem Insert the data but I'm unable to update the data. When I update nothing happens, no errors either.
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString( );
if (!IsPostBack)
{
int pi_id = Convert.ToInt32(Session["p i_id"]);
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveAn nualPhysic alValuesBy PI_ID";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = pi_id;
DataTable dtModify = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtModify);
if ((dtModify != null))
{
DataRow data = dtModify.Rows[0];
hf_ap_id.Value = data["ap_id"].ToString();
txtPhysicalDateCompleted.T ext = Convert.ToDateTime(data["a p_date"]). ToShortDat eString();
lblFileNameUploaded.Text = "Your File has been uploaded: " + data["ap_pdf_filename"].To String();
if (data["ap_section_complete "].ToStrin g() == "1")
{
btn_SaveAnnualPhysical.Ena bled = false;
cb_AnnualPhysical.Checked = true;
}
else
{
cb_AnnualPhysical.Checked = false;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
protected void btn_SaveAnnualPhysical_Cli ck(object sender, EventArgs e)
{
if (fuAnnualPhysicalForm.HasF ile)
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post edFile == null || string.IsNullOrEmpty(fuAnn ualPhysica lForm.Post edFile.Fil eName) || fuAnnualPhysicalForm.Poste dFile.Inpu tStream == null)
{
}
//Make sure we are dealing a .pdf file only
string extension = Path.GetExtension(fuAnnual PhysicalFo rm.PostedF ile.FileNa me).ToLowe r();
string MIMEType = null;
switch (extension)
{
case ".pdf":
MIMEType = "application/pdf";
break;
default:
//Invalid file type Error Message
lblUploadTypeError.Text = "Only .pdf files are allowed";
return;
}
//string MIMEType = fuAnnualPhysicalForm.Poste dFile.Cont entType;
string filename = fuAnnualPhysicalForm.Poste dFile.File Name.Split (new char[] { '\\' }).Last();
int fileSize = fuAnnualPhysicalForm.Poste dFile.Cont entLength;
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu alPhysical ";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm. PostedFile .InputStre am.Length + 1];
fuAnnualPhysicalForm.Poste dFile.Inpu tStream.Re ad(imageBy tes, 0, imageBytes.Length);
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValu e("@ap_pdf _file", SqlDbType.Image).Value = imageBytes;
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = MIMEType;
cmd.Parameters.AddWithValu e("@ap_pdf _size", SqlDbType.VarChar).Value = fileSize;
cmd.Parameters.AddWithValu e("@ap_sec tion_compl ete", SqlDbType.Int).Value = cb_AnnualPhysical.Checked;
if (string.IsNullOrEmpty(txtP hysicalDat eCompleted .Text))
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = DBNull.Value;
}
else
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = txtPhysicalDateCompleted.T ext;
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP hysical_Su ccess.aspx ");
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
hf_AppID.Value = Session["pi_id"].ToString(
if (!IsPostBack)
{
int pi_id = Convert.ToInt32(Session["p
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_RetrieveAn
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
cmd.Parameters.AddWithValu
DataTable dtModify = new DataTable("Modify");
SqlDataAdapter adp = new SqlDataAdapter();
try
{
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(dtModify);
if ((dtModify != null))
{
DataRow data = dtModify.Rows[0];
hf_ap_id.Value = data["ap_id"].ToString();
txtPhysicalDateCompleted.T
lblFileNameUploaded.Text = "Your File has been uploaded: " + data["ap_pdf_filename"].To
if (data["ap_section_complete
{
btn_SaveAnnualPhysical.Ena
cb_AnnualPhysical.Checked = true;
}
else
{
cb_AnnualPhysical.Checked = false;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
finally
{
conn.Close();
}
}
}
protected void btn_SaveAnnualPhysical_Cli
{
if (fuAnnualPhysicalForm.HasF
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post
{
}
//Make sure we are dealing a .pdf file only
string extension = Path.GetExtension(fuAnnual
string MIMEType = null;
switch (extension)
{
case ".pdf":
MIMEType = "application/pdf";
break;
default:
//Invalid file type Error Message
lblUploadTypeError.Text = "Only .pdf files are allowed";
return;
}
//string MIMEType = fuAnnualPhysicalForm.Poste
string filename = fuAnnualPhysicalForm.Poste
int fileSize = fuAnnualPhysicalForm.Poste
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm.
fuAnnualPhysicalForm.Poste
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
if (string.IsNullOrEmpty(txtP
{
cmd.Parameters.AddWithValu
}
else
{
cmd.Parameters.AddWithValu
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
}
Which one is the update code?
ASKER
btn_SaveAnnualPhysical_Cli ck is used to Insert and or Update. The SP used for this Event is listed below.
STORED PROCEDURE:
ALTER PROCEDURE [dbo].[WellnessChoice_Inse rtAnnualPh ysical]
(
@pi_id int,
@ap_date datetime,
@ap_pdf_file image,
@ap_pdf_filename varchar(50),
@ap_pdf_mime varchar(50),
@ap_pdf_size varchar(50),
@ap_section_complete int
)
AS
UPDATE WellnessChoice_AnnualPhysi cal
SET ap_date = @ap_date,
ap_pdf_file = case when DATALENGTH(@ap_pdf_file) <= 4 then ap_pdf_file else @ap_pdf_file end,
ap_pdf_filename = isnull(nullif(@ap_pdf_file name,''), ap_pdf_filename),
ap_pdf_mime = isnull(nullif(@ap_pdf_mime ,'applicat ion/octet- stream'), ap_pdf_mime),
ap_pdf_size = isnull(nullif(@ap_pdf_size ,0), ap_pdf_size),
ap_section_complete = @ap_section_complete
WHERE pi_id = @pi_id
IF @@ROWCOUNT = 0
INSERT WellnessChoice_AnnualPhysi cal (pi_id, ap_date, ap_pdf_file, ap_pdf_filename, ap_pdf_mime, ap_pdf_size, ap_section_complete)
VALUES (@pi_id, @ap_date, @ap_pdf_file, @ap_pdf_filename, @ap_pdf_mime, @ap_pdf_size, @ap_section_complete)
STORED PROCEDURE:
ALTER PROCEDURE [dbo].[WellnessChoice_Inse
(
@pi_id int,
@ap_date datetime,
@ap_pdf_file image,
@ap_pdf_filename varchar(50),
@ap_pdf_mime varchar(50),
@ap_pdf_size varchar(50),
@ap_section_complete int
)
AS
UPDATE WellnessChoice_AnnualPhysi
SET ap_date = @ap_date,
ap_pdf_file = case when DATALENGTH(@ap_pdf_file) <= 4 then ap_pdf_file else @ap_pdf_file end,
ap_pdf_filename = isnull(nullif(@ap_pdf_file
ap_pdf_mime = isnull(nullif(@ap_pdf_mime
ap_pdf_size = isnull(nullif(@ap_pdf_size
ap_section_complete = @ap_section_complete
WHERE pi_id = @pi_id
IF @@ROWCOUNT = 0
INSERT WellnessChoice_AnnualPhysi
VALUES (@pi_id, @ap_date, @ap_pdf_file, @ap_pdf_filename, @ap_pdf_mime, @ap_pdf_size, @ap_section_complete)
You cannot update the database is because if a user does not select a file, then fuAnnualPhysicalForm.HasFi le = false, then the whole block will be skipped. So according to your current logic, the update only happens when user selects a new file.
For us to better help, try explaining your business logic a bit more.
For us to better help, try explaining your business logic a bit more.
ASKER
Step 1: need the ability to upload a file.
Step 2: need ability to NOT overwrite and existing file if one is already present in the DB when just performing an update on another field.
Step 3: need ability to update file and it's info if user decides to reupload another file.
Please note: That if I use the following code below all my steps above work fine. The only problem that I have is when trying to ONLY specify that a user has to upload PDF files only.
THIS CODE WORKS AS NEEDED BELOW, I JUST NEED TO MAKE IT SO THAT THEY ONLY CAN UPLOAD PDF FILES:
protected void btn_SaveAnnualPhysical_Cli ck(object sender, EventArgs e)
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post edFile == null || string.IsNullOrEmpty(fuAnn ualPhysica lForm.Post edFile.Fil eName) || fuAnnualPhysicalForm.Poste dFile.Inpu tStream == null)
{
}
string MIMEType = fuAnnualPhysicalForm.Poste dFile.Cont entType;
string filename = fuAnnualPhysicalForm.Poste dFile.File Name.Split (new char[] { '\\' }).Last();
int fileSize = fuAnnualPhysicalForm.Poste dFile.Cont entLength;
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu alPhysical ";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm. PostedFile .InputStre am.Length + 1];
fuAnnualPhysicalForm.Poste dFile.Inpu tStream.Re ad(imageBy tes, 0, imageBytes.Length);
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValu e("@ap_pdf _file", SqlDbType.Image).Value = imageBytes;
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = MIMEType;
cmd.Parameters.AddWithValu e("@ap_pdf _size", SqlDbType.VarChar).Value = fileSize;
cmd.Parameters.AddWithValu e("@ap_sec tion_compl ete", SqlDbType.Int).Value = cb_AnnualPhysical.Checked;
if (string.IsNullOrEmpty(txtP hysicalDat eCompleted .Text))
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = DBNull.Value;
}
else
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = txtPhysicalDateCompleted.T ext;
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP hysical_Su ccess.aspx ");
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
Step 2: need ability to NOT overwrite and existing file if one is already present in the DB when just performing an update on another field.
Step 3: need ability to update file and it's info if user decides to reupload another file.
Please note: That if I use the following code below all my steps above work fine. The only problem that I have is when trying to ONLY specify that a user has to upload PDF files only.
THIS CODE WORKS AS NEEDED BELOW, I JUST NEED TO MAKE IT SO THAT THEY ONLY CAN UPLOAD PDF FILES:
protected void btn_SaveAnnualPhysical_Cli
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post
{
}
string MIMEType = fuAnnualPhysicalForm.Poste
string filename = fuAnnualPhysicalForm.Poste
int fileSize = fuAnnualPhysicalForm.Poste
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm.
fuAnnualPhysicalForm.Poste
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
if (string.IsNullOrEmpty(txtP
{
cmd.Parameters.AddWithValu
}
else
{
cmd.Parameters.AddWithValu
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
In your original post, you mentioned your problem is " if the user does not select a file to upload then the code does not execute and instead the page postback to itself. " However, in your post above, you said "Please note: That if I use the following code below all my steps above work fine. The only problem that I have is when trying to ONLY specify that a user has to upload PDF files only."
Those are two different problems.
Did you think that file extension check in your OP introduced the first problem? Based on the code you provided, you have the same problem when user does not select a file, no matter you have file extension check or not. If user does not select a file, and if you don't check fuAnnualPhysicalForm.HasFi le, then fuAnnualPhysicalForm.Poste dFile.File Name will give you a null reference error. Did you get any exception error with your original code when user does not select a file?
I suggest you to have a block for handling fuAnnualPhysicalForm.HasFi le = true, then have a else block to handle fuAnnualPhysicalForm.HasFi le = false.
Those are two different problems.
Did you think that file extension check in your OP introduced the first problem? Based on the code you provided, you have the same problem when user does not select a file, no matter you have file extension check or not. If user does not select a file, and if you don't check fuAnnualPhysicalForm.HasFi
I suggest you to have a block for handling fuAnnualPhysicalForm.HasFi
protected void btn_SaveAnnualPhysical_Click(object sender, EventArgs e)
{
if (fuAnnualPhysicalForm.HasFile)
{
// your other code here
}
else
{
// update other information
}
}
ASKER
Hi codingbeaver,
I apologize, I'm thinking about something different. You are correct.
Now I remember, sorry, have been at this for awhile :(
I need to make sure that the user is ONLY uploading a PDF file and if so execute the btn_SaveAnnualPhysical Code. If file is NOT pdf then display message to label control.
If a user decideds to ONLY insert/update a another field other than the FileUpload Control then allow to go through. If a user would like to overwrite the File with another PDF file then allow.
Where do I place the code I have now and a what section to your above post?
I apologize, I'm thinking about something different. You are correct.
Now I remember, sorry, have been at this for awhile :(
I need to make sure that the user is ONLY uploading a PDF file and if so execute the btn_SaveAnnualPhysical Code. If file is NOT pdf then display message to label control.
If a user decideds to ONLY insert/update a another field other than the FileUpload Control then allow to go through. If a user would like to overwrite the File with another PDF file then allow.
Where do I place the code I have now and a what section to your above post?
Here is the basic logic you can refer to:
If you have trouble understanding the above logic, let me know.
protected void btn_SaveAnnualPhysical_Click(object sender, EventArgs e)
{
if (fuAnnualPhysicalForm.HasFile)
{
// user has uploaded a file
// check file extension here
// if file extension is ok
// then proceed to update/insert record
// if file extension is not OK
// display error message and stop
}
else
{
// user does not select a new file to upload
// then insert/update other fields other than
// the FileUpload control field
}
}
If you have trouble understanding the above logic, let me know.
ASKER
Hi codingbeaver,
Ok, sorry for the delay. I believe I understood what you meant. So I made the following changes below and everything seems fine. Would you mind looking over the code below and giving me your thoughts?
Thanks again for your help and support!!!!
protected void btn_SaveAnnualPhysical_Cli ck(object sender, EventArgs e)
{
if (fuAnnualPhysicalForm.HasF ile)
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post edFile == null || string.IsNullOrEmpty(fuAnn ualPhysica lForm.Post edFile.Fil eName) || fuAnnualPhysicalForm.Poste dFile.Inpu tStream == null)
{
}
//Make sure we are dealing a .pdf file only
string extension = Path.GetExtension(fuAnnual PhysicalFo rm.PostedF ile.FileNa me).ToLowe r();
string MIMEType = null;
switch (extension)
{
case ".pdf":
MIMEType = "application/pdf";
break;
default:
//Invalid file type Error Message
lblUploadTypeError.Text = "Only .pdf files are allowed";
return;
}
// string MIMEType = fuAnnualPhysicalForm.Poste dFile.Cont entType;
string filename = fuAnnualPhysicalForm.Poste dFile.File Name.Split (new char[] { '\\' }).Last();
int fileSize = fuAnnualPhysicalForm.Poste dFile.Cont entLength;
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu alPhysical ";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm. PostedFile .InputStre am.Length + 1];
fuAnnualPhysicalForm.Poste dFile.Inpu tStream.Re ad(imageBy tes, 0, imageBytes.Length);
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValu e("@ap_pdf _file", SqlDbType.Image).Value = imageBytes;
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = MIMEType;
cmd.Parameters.AddWithValu e("@ap_pdf _size", SqlDbType.VarChar).Value = fileSize;
cmd.Parameters.AddWithValu e("@ap_sec tion_compl ete", SqlDbType.Int).Value = cb_AnnualPhysical.Checked;
if (string.IsNullOrEmpty(txtP hysicalDat eCompleted .Text))
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = DBNull.Value;
}
else
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = txtPhysicalDateCompleted.T ext;
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP hysical_Su ccess.aspx ");
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
else
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post edFile == null || string.IsNullOrEmpty(fuAnn ualPhysica lForm.Post edFile.Fil eName) || fuAnnualPhysicalForm.Poste dFile.Inpu tStream == null)
{
}
string MIMEType = fuAnnualPhysicalForm.Poste dFile.Cont entType;
string filename = fuAnnualPhysicalForm.Poste dFile.File Name.Split (new char[] { '\\' }).Last();
int fileSize = fuAnnualPhysicalForm.Poste dFile.Cont entLength;
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu alPhysical ";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm. PostedFile .InputStre am.Length + 1];
fuAnnualPhysicalForm.Poste dFile.Inpu tStream.Re ad(imageBy tes, 0, imageBytes.Length);
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValu e("@ap_pdf _file", SqlDbType.Image).Value = imageBytes;
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = MIMEType;
cmd.Parameters.AddWithValu e("@ap_pdf _size", SqlDbType.VarChar).Value = fileSize;
cmd.Parameters.AddWithValu e("@ap_sec tion_compl ete", SqlDbType.Int).Value = cb_AnnualPhysical.Checked;
if (string.IsNullOrEmpty(txtP hysicalDat eCompleted .Text))
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = DBNull.Value;
}
else
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = txtPhysicalDateCompleted.T ext;
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP hysical_Su ccess.aspx ");
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
Ok, sorry for the delay. I believe I understood what you meant. So I made the following changes below and everything seems fine. Would you mind looking over the code below and giving me your thoughts?
Thanks again for your help and support!!!!
protected void btn_SaveAnnualPhysical_Cli
{
if (fuAnnualPhysicalForm.HasF
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post
{
}
//Make sure we are dealing a .pdf file only
string extension = Path.GetExtension(fuAnnual
string MIMEType = null;
switch (extension)
{
case ".pdf":
MIMEType = "application/pdf";
break;
default:
//Invalid file type Error Message
lblUploadTypeError.Text = "Only .pdf files are allowed";
return;
}
// string MIMEType = fuAnnualPhysicalForm.Poste
string filename = fuAnnualPhysicalForm.Poste
int fileSize = fuAnnualPhysicalForm.Poste
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm.
fuAnnualPhysicalForm.Poste
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
if (string.IsNullOrEmpty(txtP
{
cmd.Parameters.AddWithValu
}
else
{
cmd.Parameters.AddWithValu
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
else
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post
{
}
string MIMEType = fuAnnualPhysicalForm.Poste
string filename = fuAnnualPhysicalForm.Poste
int fileSize = fuAnnualPhysicalForm.Poste
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm.
fuAnnualPhysicalForm.Poste
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
if (string.IsNullOrEmpty(txtP
{
cmd.Parameters.AddWithValu
}
else
{
cmd.Parameters.AddWithValu
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
1. If fuAnnualPhysicalForm.HasFi le = true then this block is always false and wil not be executed at all:
if (fuAnnualPhysicalForm.Post edFile == null || string.IsNullOrEmpty(fuAnn ualPhysica lForm.Post edFile.Fil eName) || fuAnnualPhysicalForm.Poste dFile.Inpu tStream == null)
{
}
so you don't need this block.
2. If fuAnnualPhysicalForm.HasFi le = false, the above block is always true, but you have nothing in the block, so you don't need it either.
3. In your else block, because fuAnnualPhysicalForm.HasFi le = false, no file has been uploaded, you should not try to get the file information from fuAnnualPhysicalForm.Poste dFile. Also, since no file is uploaded, why do you still try to update the file information in your database?
if (fuAnnualPhysicalForm.Post
{
}
so you don't need this block.
2. If fuAnnualPhysicalForm.HasFi
3. In your else block, because fuAnnualPhysicalForm.HasFi
ASKER
Ok, I believe I did Step 1 correctly but not sure what to change for Step 2.
>> Also, since no file is uploaded, why do you still try to update the file information in your database?
I believe the reason I did that is because my Save btn handles both Insert/Updates SP. So wouldn't I still need that for Step 2 in case a user wants to upload another file? If not needed can you modify the following code below to what I should have if need be?
protected void btn_SaveAnnualPhysical_Cli ck(object sender, EventArgs e)
{
if (fuAnnualPhysicalForm.HasF ile)
{
//// Make sure a file has been successfully uploaded
//if (fuAnnualPhysicalForm.Post edFile == null || string.IsNullOrEmpty(fuAnn ualPhysica lForm.Post edFile.Fil eName) || fuAnnualPhysicalForm.Poste dFile.Inpu tStream == null)
//{
//}
//Make sure we are dealing a .pdf file only
string extension = Path.GetExtension(fuAnnual PhysicalFo rm.PostedF ile.FileNa me).ToLowe r();
string MIMEType = null;
switch (extension)
{
case ".pdf":
MIMEType = "application/pdf";
break;
default:
//Invalid file type Error Message
lblUploadTypeError.Text = "Only .pdf files are allowed";
return;
}
// string MIMEType = fuAnnualPhysicalForm.Poste dFile.Cont entType;
string filename = fuAnnualPhysicalForm.Poste dFile.File Name.Split (new char[] { '\\' }).Last();
int fileSize = fuAnnualPhysicalForm.Poste dFile.Cont entLength;
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu alPhysical ";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm. PostedFile .InputStre am.Length + 1];
fuAnnualPhysicalForm.Poste dFile.Inpu tStream.Re ad(imageBy tes, 0, imageBytes.Length);
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValu e("@ap_pdf _file", SqlDbType.Image).Value = imageBytes;
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = MIMEType;
cmd.Parameters.AddWithValu e("@ap_pdf _size", SqlDbType.VarChar).Value = fileSize;
cmd.Parameters.AddWithValu e("@ap_sec tion_compl ete", SqlDbType.Int).Value = cb_AnnualPhysical.Checked;
if (string.IsNullOrEmpty(txtP hysicalDat eCompleted .Text))
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = DBNull.Value;
}
else
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = txtPhysicalDateCompleted.T ext;
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP hysical_Su ccess.aspx ");
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
else
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post edFile == null || string.IsNullOrEmpty(fuAnn ualPhysica lForm.Post edFile.Fil eName) || fuAnnualPhysicalForm.Poste dFile.Inpu tStream == null)
{
}
string MIMEType = fuAnnualPhysicalForm.Poste dFile.Cont entType;
string filename = fuAnnualPhysicalForm.Poste dFile.File Name.Split (new char[] { '\\' }).Last();
int fileSize = fuAnnualPhysicalForm.Poste dFile.Cont entLength;
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["We llnessChoi ce"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu alPhysical ";
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm. PostedFile .InputStre am.Length + 1];
fuAnnualPhysicalForm.Poste dFile.Inpu tStream.Re ad(imageBy tes, 0, imageBytes.Length);
cmd.Parameters.AddWithValu e("@pi_id" , SqlDbType.Int).Value = hf_AppID.Value;
cmd.Parameters.AddWithValu e("@ap_pdf _file", SqlDbType.Image).Value = imageBytes;
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = MIMEType;
cmd.Parameters.AddWithValu e("@ap_pdf _size", SqlDbType.VarChar).Value = fileSize;
cmd.Parameters.AddWithValu e("@ap_sec tion_compl ete", SqlDbType.Int).Value = cb_AnnualPhysical.Checked;
if (string.IsNullOrEmpty(txtP hysicalDat eCompleted .Text))
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = DBNull.Value;
}
else
{
cmd.Parameters.AddWithValu e("@ap_dat e", SqlDbType.DateTime).Value = txtPhysicalDateCompleted.T ext;
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP hysical_Su ccess.aspx ");
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
>> Also, since no file is uploaded, why do you still try to update the file information in your database?
I believe the reason I did that is because my Save btn handles both Insert/Updates SP. So wouldn't I still need that for Step 2 in case a user wants to upload another file? If not needed can you modify the following code below to what I should have if need be?
protected void btn_SaveAnnualPhysical_Cli
{
if (fuAnnualPhysicalForm.HasF
{
//// Make sure a file has been successfully uploaded
//if (fuAnnualPhysicalForm.Post
//{
//}
//Make sure we are dealing a .pdf file only
string extension = Path.GetExtension(fuAnnual
string MIMEType = null;
switch (extension)
{
case ".pdf":
MIMEType = "application/pdf";
break;
default:
//Invalid file type Error Message
lblUploadTypeError.Text = "Only .pdf files are allowed";
return;
}
// string MIMEType = fuAnnualPhysicalForm.Poste
string filename = fuAnnualPhysicalForm.Poste
int fileSize = fuAnnualPhysicalForm.Poste
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm.
fuAnnualPhysicalForm.Poste
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
if (string.IsNullOrEmpty(txtP
{
cmd.Parameters.AddWithValu
}
else
{
cmd.Parameters.AddWithValu
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
else
{
// Make sure a file has been successfully uploaded
if (fuAnnualPhysicalForm.Post
{
}
string MIMEType = fuAnnualPhysicalForm.Poste
string filename = fuAnnualPhysicalForm.Poste
int fileSize = fuAnnualPhysicalForm.Poste
// Allow only files less than 1,048,576 bytes (approximately 1 MB) to be uploaded.
if ((fileSize < 1048576))
{
SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "WellnessChoice_InsertAnnu
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = conn;
// Load PDF InputStream into Byte array
byte[] imageBytes = new byte[fuAnnualPhysicalForm.
fuAnnualPhysicalForm.Poste
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
if (string.IsNullOrEmpty(txtP
{
cmd.Parameters.AddWithValu
}
else
{
cmd.Parameters.AddWithValu
}
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblSaveError.Text = ("Error on insert: " + ex.Message.ToString());
}
finally
{
Response.Redirect("AnnualP
conn.Close();
}
}
else
{
lblFileSize.Text = "Your File has to be 5 MB or smaller";
}
}
>>>I believe the reason I did that is because my Save btn handles both Insert/Updates SP. So wouldn't I still need that for Step 2 in case a user wants to upload another file?
If user wants to upload another file and does select a file, then fuAnnualPhysicalForm.HasFi le = true, so your code will execute the "if" block, instead of the "else" block. Does it make sense?
(fuAnnualPhysicalForm.HasF ile is used to check if a file has been uploaded).
>>>If not needed can you modify the following code below to what I should have if need be?
If user chooses not to upload a file and clicks Save button, what information do you allow to update in database?
If user wants to upload another file and does select a file, then fuAnnualPhysicalForm.HasFi
(fuAnnualPhysicalForm.HasF
>>>If not needed can you modify the following code below to what I should have if need be?
If user chooses not to upload a file and clicks Save button, what information do you allow to update in database?
ASKER
>> If user chooses not to upload a file and clicks Save button, what information do you allow to update in database?
I apologize if I'm not making sense or confusing. Let me try to explain a little better.
Option 1: User uploads PDF FIle only
Option 2: User may NOT upload PDF file and he /she may only Insert / Update Date in txtPhysicalDateCompleted control.
Option 3: User may need to overwrite previous file that they uploaded if they made a mistake and uploaded wrong file, if so overwrite file in DB with new file.
Option 4:
I apologize if I'm not making sense or confusing. Let me try to explain a little better.
Option 1: User uploads PDF FIle only
Option 2: User may NOT upload PDF file and he /she may only Insert / Update Date in txtPhysicalDateCompleted control.
Option 3: User may need to overwrite previous file that they uploaded if they made a mistake and uploaded wrong file, if so overwrite file in DB with new file.
Option 4:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I copied your code but when the page first loads I get the following message below.
Error is on line 196.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1011: Empty character literal
Source Error:
Line 194:
Line 195: //cmd.Parameters.AddWithVa lue("@ap_p df_filenam e", SqlDbType.VarChar).Value = filename;
Line 196: cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = '';
Line 197:
Line 198: //cmd.Parameters.AddWithVa lue("@ap_p df_mime", SqlDbType.VarChar).Value = MIMEType;
Error is on line 196.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1011: Empty character literal
Source Error:
Line 194:
Line 195: //cmd.Parameters.AddWithVa
Line 196: cmd.Parameters.AddWithValu
Line 197:
Line 198: //cmd.Parameters.AddWithVa
Sorry, replace single quote to double quote.
//cmd.Parameters.AddWithValue("@ap_pdf_filename", SqlDbType.VarChar).Value = filename;
cmd.Parameters.AddWithValue("@ap_pdf_filename", SqlDbType.VarChar).Value = "";
//cmd.Parameters.AddWithValue("@ap_pdf_mime", SqlDbType.VarChar).Value = MIMEType;
cmd.Parameters.AddWithValue("@ap_pdf_mime", SqlDbType.VarChar).Value = "application/octet-stream";
ASKER
Hi codingbeaver:,
I found the problem. Please see below. And if that's all and nothing else needs changed let me know so that I can close the post. Thank you for your time, patience, and willing to help others!!!!!
DID NOT WORK: (SINGLE QUOTES)
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = '';
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = "application/octet-stream" ;
WORKED AS NEEDED WITH NO ISSUES FOR INSERT/UPDATE:
cmd.Parameters.AddWithValu e("@ap_pdf _filename" , SqlDbType.VarChar).Value = "";
cmd.Parameters.AddWithValu e("@ap_pdf _mime", SqlDbType.VarChar).Value = "application/octet-stream" ;
I found the problem. Please see below. And if that's all and nothing else needs changed let me know so that I can close the post. Thank you for your time, patience, and willing to help others!!!!!
DID NOT WORK: (SINGLE QUOTES)
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
WORKED AS NEEDED WITH NO ISSUES FOR INSERT/UPDATE:
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
ASKER
Hi codingbeaver,
Yes, that worked...
Thank you for your time, patience, and willing to help others!!!!!
Yes, that worked...
Thank you for your time, patience, and willing to help others!!!!!
I am glad it works now.
ASKER
Thank you again for your time, patience and willing to help with this post. I truly apprecieate it!!!