I have an asp.net web forms web application and I save uploaded images with binary formats in database and then for loading the images I convert the binary data to base64 string and load it,in my local server when I run visual studio it works fine with not any problem,but unfortuantly when I publish it to a server then after choose file it can't upload the image and it gets this exception error : Could not find file 'c:\windows\system32\inetsrv\download (2).jpg'.,could you please tell me what can I do? thanks a lot.
var ImageCode = tools.UploadFileToDatabase(file, "اخبار");
public int UploadFileToDatabase(HttpPostedFile file,string FileSubject)
{
var extension = GetFileExtension(file.FileName);
byte[] ByteFile = FileToByteArray(file.FileName);
BOLAmlakFiles bOLAmlakFiles = new BOLAmlakFiles();
var resultCode = bOLAmlakFiles.InsertFile(file.FileName, ByteFile, FileSubject,
extension);
return resultCode;
}
public byte[] FileToByteArray(string fileName)
{
byte[] fileContent = null;
System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fs);
long byteLength = new System.IO.FileInfo(fileName).Length;
fileContent = binaryReader.ReadBytes((Int32)byteLength);
fs.Close();
fs.Dispose();
binaryReader.Close();
return fileContent;
}
public int InsertFile(string name, byte[] content, string category,
string FileExtension)
{
try
{
Files ObjTable = new Files();
dataContext.Files.InsertOnSubmit(ObjTable);
ObjTable.Name = name;
ObjTable.Content = content;
ObjTable.Category = category;
ObjTable.CreationDate = DateTime.Now;
ObjTable.FileExtencion = FileExtension;
dataContext.SubmitChanges();
dataContext.Connection.Close();
return ObjTable.Code;
}
catch (Exception)
{
return 0;
}