G
Guest
I'm converting a Delphi app to C#. The application uploads and downloads
files to an image field on SQL through a webservice. With Delphi, this was
done straight to SQL instead of a webservice. The C# code works fine in both
directions except in the case of zip files. I get a message, from WinZip,
telling me that the archive is not valid. The zip is valid, in the sql
server, becuase it can be opened when using my old Delphi version of this
program. I can also upload the zips with the C# version and open them with
the Delphi version so I'm pretty sure it how the file is being re-created
using C#.
Below is the code that I use to download and open the file Any help would be
appreciated.
TIA
//Get the document from the table
DataRow rowDataImage = null;
DataRowView rowData =
DataRowView)BindingContext[dsLibrary.Tables["AvailDocs"]].Current;
DataSet ds = DB.getDoc(System.Convert.ToInt32(rowData[0].ToString()));
string strDocExt =
DB.getDocFileExt(System.Convert.ToInt32(rowData[0].ToString()));
rowDataImage=ds.Tables[0].Rows[0];
//Read the image from the table field into a byte array
byte[] MyData= new byte[0];
MyData = (byte[])rowDataImage[0];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
//Create a destination for the file
FileStream fs = new FileStream("c:\\elibtemp." + strDocExt,
FileMode.Create,FileAccess.Write,FileShare.Write,ArraySize,true);
// Create the writer for data.
fs.Write(MyData, 0,ArraySize);
fs.Close();
files to an image field on SQL through a webservice. With Delphi, this was
done straight to SQL instead of a webservice. The C# code works fine in both
directions except in the case of zip files. I get a message, from WinZip,
telling me that the archive is not valid. The zip is valid, in the sql
server, becuase it can be opened when using my old Delphi version of this
program. I can also upload the zips with the C# version and open them with
the Delphi version so I'm pretty sure it how the file is being re-created
using C#.
Below is the code that I use to download and open the file Any help would be
appreciated.
TIA
//Get the document from the table
DataRow rowDataImage = null;
DataRowView rowData =
DataRowView)BindingContext[dsLibrary.Tables["AvailDocs"]].Current;
DataSet ds = DB.getDoc(System.Convert.ToInt32(rowData[0].ToString()));
string strDocExt =
DB.getDocFileExt(System.Convert.ToInt32(rowData[0].ToString()));
rowDataImage=ds.Tables[0].Rows[0];
//Read the image from the table field into a byte array
byte[] MyData= new byte[0];
MyData = (byte[])rowDataImage[0];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
//Create a destination for the file
FileStream fs = new FileStream("c:\\elibtemp." + strDocExt,
FileMode.Create,FileAccess.Write,FileShare.Write,ArraySize,true);
// Create the writer for data.
fs.Write(MyData, 0,ArraySize);
fs.Close();