Hi,
Im uploading a file using RadAsyncUpload control and I wanted to check if the image to be uploaded is really image, not just another file changed of extension name. Code below:
The error is triggered on the .SaveAs() function
String fileExt = rfile_image.UploadedFiles[0].FileName.Substring(rfile_image.UploadedFiles[0].FileName.LastIndexOf('.') + 1).ToUpper();
byte[] tmp = imageHeader[fileExt];
byte[] header = new byte[tmp.Length];
rfile_image.UploadedFiles[0].InputStream.Read(header, 0, header.Length);
if (!CompareArray(tmp, header))
{
//invalid content type
rfile_image.Dispose();
rfile_image.UploadedFiles[0].InputStream.Close();
rfile_image.UploadedFiles[0].InputStream.Dispose();
returnError("Filename Invalid");
}
else
{
//valid content type, continue with saving
fileUrl = "C:\\data\\" + fileWithPath;
rfile_image.UploadedFiles[0].SaveAs(fileUrl,true);
}
Im uploading a file using RadAsyncUpload control and I wanted to check if the image to be uploaded is really image, not just another file changed of extension name. Code below:
The error is triggered on the .SaveAs() function
String fileExt = rfile_image.UploadedFiles[0].FileName.Substring(rfile_image.UploadedFiles[0].FileName.LastIndexOf('.') + 1).ToUpper();
byte[] tmp = imageHeader[fileExt];
byte[] header = new byte[tmp.Length];
rfile_image.UploadedFiles[0].InputStream.Read(header, 0, header.Length);
if (!CompareArray(tmp, header))
{
//invalid content type
rfile_image.Dispose();
rfile_image.UploadedFiles[0].InputStream.Close();
rfile_image.UploadedFiles[0].InputStream.Dispose();
returnError("Filename Invalid");
}
else
{
//valid content type, continue with saving
fileUrl = "C:\\data\\" + fileWithPath;
rfile_image.UploadedFiles[0].SaveAs(fileUrl,true);
}