Hi,
I am using an RadAsyncUpload inside my grid, to upload a single file. When in edit mode, the existing file is supposed to be overwritten. But this is not the case. I have tried with several different ways to create the file (my example here is the last one) - I have also tried using File.WriteAllBytes. This is my code:
In create mode, the file is created perfectly...
I am using an RadAsyncUpload inside my grid, to upload a single file. When in edit mode, the existing file is supposed to be overwritten. But this is not the case. I have tried with several different ways to create the file (my example here is the last one) - I have also tried using File.WriteAllBytes. This is my code:
In create mode, the file is created perfectly...
Control asyncUpload1 = editableItem.EditManager.GetColumnEditor(
"FileNameWithExtension"
).ContainerControl.FindControl(
"AsyncUpload1"
);
if
(asyncUpload1 !=
null
&& asyncUpload1
is
RadAsyncUpload)
{
if
(((RadAsyncUpload)asyncUpload1).UploadedFiles.Count > 0)
{
UploadedFile uploadedFile = ((RadAsyncUpload)asyncUpload1).UploadedFiles[0];
if
(letterTemplate.FileNameWithExtension != uploadedFile.FileName && letterTemplate.FileNameWithExtension !=
null
)
{
File.Delete(GetTemplatePath(letterTemplate.MunicipalityCode, letterTemplate.FileNameWithExtension));
}
letterTemplate.FileNameWithExtension = uploadedFile.FileName;
byte
[] buffer =
new
byte
[uploadedFile.InputStream.Length + 1];
uploadedFile.InputStream.Read(buffer, 0, buffer.Length);
CreateDirectoryIfNotExistent(Server.MapPath(
string
.Format(TEMPLATE_PATH, letterTemplate.MunicipalityCode)));
using
(FileStream stream =
new
FileStream(GetTemplatePath(letterTemplate.MunicipalityCode, letterTemplate.FileNameWithExtension), FileMode.Create))
{
stream.Write(buffer, 0, buffer.Length);
}
}
else
if
(e.CommandName == CMD_CREATE)
{
Label error = (Label)editableItem.EditManager.GetColumnEditor(
"FileNameWithExtension"
).ContainerControl.FindControl(
"lblError"
);
error.Text =
"Angiv en Word skabelon-fil."
;
return
;
}
}