Hope someone can help me. I've got a database where i store files (the binary content).
What i would like to do is use the asyncfileupload to check that after the file gets uploaded if it exists in the database already or not.
Here is how i've got my code so far:
byte[] imageBytes = new byte[AsyncFileUpload1.PostedFile.ContentLength + 1];
AsyncFileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length);
string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection Connection = new SqlConnection(strConnection);
string strSelectQuery = "SELECT BinaryData from Attachments where (DataLength(BinaryData)=DataLength('" + data + "'))";
SqlCommand Command = new SqlCommand(strSelectQuery, Connection);
Connection.Open();
SqlDataReader reader = Command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
imgValidFail.Visible = true;
lblValidFail.Visible = true;
}
}
else
{
imgValidPass.Visible = true;
lblValidPass.Visible = true;
}
I doubt whether with async file upload you can do this, as it will check at OnUploadedComplete at server side and OnClientUploadComplete at client side. check below link for more
info :-
jonpwatson3
Member
1 Points
2 Posts
asyncfileupload - Check binary against database
Feb 22, 2012 03:03 PM|LINK
Hi.
Hope someone can help me. I've got a database where i store files (the binary content).
What i would like to do is use the asyncfileupload to check that after the file gets uploaded if it exists in the database already or not.
Here is how i've got my code so far:
byte[] imageBytes = new byte[AsyncFileUpload1.PostedFile.ContentLength + 1]; AsyncFileUpload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length); string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection Connection = new SqlConnection(strConnection); string strSelectQuery = "SELECT BinaryData from Attachments where (DataLength(BinaryData)=DataLength('" + data + "'))"; SqlCommand Command = new SqlCommand(strSelectQuery, Connection); Connection.Open(); SqlDataReader reader = Command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { imgValidFail.Visible = true; lblValidFail.Visible = true; } } else { imgValidPass.Visible = true; lblValidPass.Visible = true; }Many thanks!
Jon
chetan.sarod...
All-Star
66629 Points
11270 Posts
Re: asyncfileupload - Check binary against database
Feb 23, 2012 02:41 AM|LINK
I doubt whether with async file upload you can do this, as it will check at OnUploadedComplete at server side and OnClientUploadComplete at client side. check below link for more info :-
AsynFileUpload Control and its Validation
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.