I'm using a custom SendEmailAfterSubmissionActor where i override the method Send. The reason if for attaching files to email when user is uploading files in my form. CopyTo method in postFile.InputStream to MemoryStream i get this error.
StackTrace = " at System.IO.__Error.FileNotOpen()\r\n at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin)\r\n at System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)\r\n at Test.Web.Extensions.EpiserverForms
Here is the full code for getting my files.
private List<UploadedFile> GetUploadedFiles()
{
var uploadedFiles = new List<UploadedFile>();
try
{
for (int i = 0; i < this.HttpRequestContext.Files.Count; i++)
{
HttpPostedFileBase postedFile = this.HttpRequestContext.Files[i];
postedFile.InputStream.Position = 0;
postedFile.InputStream.Seek(0, SeekOrigin.Begin);
MemoryStream memoryStream = new MemoryStream();
postedFile.InputStream.CopyTo(memoryStream);
memoryStream.Position = 0;
memoryStream.Seek(0, SeekOrigin.Begin);
uploadedFiles.Add(
new UploadedFile()
{
Name = postedFile.FileName,
Type = MimeMapping.GetMimeMapping(postedFile.FileName),
InputStream = memoryStream
});
}
}
catch (Exception ex)
{
PostSubmissionActorBase._logger.Error("Failed to get uploaded files:
{0}", ex);
}
return uploadedFiles;
}
I'm using a custom SendEmailAfterSubmissionActor where i override the method Send. The reason if for attaching files to email when user is uploading files in my form.
CopyTo method in postFile.InputStream to MemoryStream i get this error.StackTrace = " at System.IO.__Error.FileNotOpen()\r\n at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin)\r\n at System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)\r\n at Test.Web.Extensions.EpiserverForms