Hi,
I am trying to upload an image using the radupload control and save it on the file system.
I need to convert the file stream to a byte array and then save it.
While debugging, i found that
coll[0].InputStream.Read(byteFile, 0, byteFile.Length + 1);
the byteFile has 0 in all the position (which means its a corrupted file).
Can you please provide the code using which i can convert this input stream into byte array and save it on the file system?
I am trying to upload an image using the radupload control and save it on the file system.
I need to convert the file stream to a byte array and then save it.
While debugging, i found that
coll[0].InputStream.Read(byteFile, 0, byteFile.Length + 1);
the byteFile has 0 in all the position (which means its a corrupted file).
Can you please provide the code using which i can convert this input stream into byte array and save it on the file system?
foreach (RepeaterItem item in this.uploadRepeater.Items)
{
int imageId;
UploadedFileCollection coll = ((RadUpload)item.FindControl("radUpload")).UploadedFiles;
RadUpload up = ((RadUpload)item.FindControl("radUpload"));
if (null != coll && 0 != coll.Count)
{
fileManager = new FileManager(coll);
isImageValid = isImageValid & fileManager.ValidateFile();
if (true == isImageValid)
{
byte[] byteFile = new byte[coll[0].InputStream.Length];
coll[0].InputStream.Read(byteFile, 0, byteFile.Length + 1); // reading into //a byte arrary. Here while debugging, i see that all location in the array have value 0.
Guid guid = this.SaveFileToDisk(byteFile , coll[0].GetExtension());
}
else
{
// show error message
}
}
}
public static Guid SaveFileToDisk(byte[] fileBytes, string fileExtension)
{
Guid imageGuid = Guid.Empty;
FileStream stream = null;
imageGuid = Guid.NewGuid();
string fileLocation = ConfigurationManager.Configurations().ImageSaveLocation + imageGuid + "." + fileExtension;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Open file for reading .
using (stream = new FileStream(fileLocation, FileMode.Create, FileAccess.Write))
{
// Writes a block of bytes to this stream using data from a byte array.
stream.Write(fileBytes, 0, fileBytes.Length);
}
});
return imageGuid;
}