0
在sitefinity中,我的表單包含文件上傳控件。如何將文件上傳值設置爲已選擇的文件?我試圖以編程方式設置窗體的值。以下是我到目前爲止:表單響應文件上傳
//Enquiry Test
entry.SetValue("FormParagraphTextBox_C007", "Test sample");
int count = 0;
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
var contentTtype = Request.Files[i].ContentType;
string extension = Path.GetExtension(file.FileName).ToLower();
if (ValidFileFormats.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Contains(extension))
{
MIMETypeChecker mc = new MIMETypeChecker();
if (contentTtype == mc.GetMIMEType(file.FileName))
{
byte[] fileBytes;
using (var binaryReader = new BinaryReader(file.InputStream))
{
fileBytes = binaryReader.ReadBytes(Request.Files[i].ContentLength);
}
DirectoryInfo dir = new DirectoryInfo(ConfigurationManager.AppSettings["EnquiriesUploadPath"] + Member.MemberNumber + "/" + refNrNe.ReferenceNumber);
if (!dir.Exists)
dir.Create();
if (dir.GetFiles().Count() < 11)
{
using (FileStream fs = new FileStream(dir.FullName + "/" + file.FileName, FileMode.Create, FileAccess.ReadWrite))
{
fs.Write(fileBytes, 0, fileBytes.Length);
}
}
}
}
}
//Attatchment Upload
entry.SetValue("FormFileUpload_C008", null);
用戶是選擇files.Hence的「Request.Files」我現在開始認爲這可能是我最好的選擇。 [鏈接](http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/how-to-programmatically-associate-document-upload-to-form-response-entry) –