Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My application allows users to upload single files at a time. Some of my users (external) to my network are uploading the fileupoad control type rather than the actual file.

So instead of uploading the file they upload the control type name below instead.

System.Web.UI.WebControls.FileUpload

What I have tried:

C#
if (File.Exists(savePath)) File.Delete(savePath);
  fleUpload.SaveAs(savePath);

  SqlConnection con = new SqlConnection(getConnectionString("dbConn").ToString());
  SqlCommand sqlCmd = new SqlCommand("update [dbo].[table] set fieldX = @imgPath where code = @Code and [A#] = @clientNum", con);
  sqlCmd.Parameters.Add("@imgPath", SqlDbType.VarChar).Value = imagePath;
  sqlCmd.Parameters.Add("@clientNum", SqlDbType.VarChar).Value = oARegNum;
  sqlCmd.Parameters.Add("@providerCode", SqlDbType.VarChar).Value = providerCode;
  con.Open();
  sqlCmd.ExecuteNonQuery();
  con.Close();
Posted
Updated 18-Sep-19 3:40am
v2
Comments
Richard Deeming 19-Sep-19 12:41pm    
Where is the code that initializes the savePath and imagePath variables?

Your problem is way before this code; all this portion does is save the file and store the path in the database.

Your problem is with the block of code receiving the file; which you obviously are not validating as it makes it to the database.

What you may want to look at is what the end users were uploading; if anything.
 
Share this answer
 
Comments
Member 10548977 18-Sep-19 8:24am    
Can you think of anything else?
One thing I discovered is this. When a file is selected but then removed from the upload control. The control text box retains the selected file even after being deleted from the control.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900