我正在实施一些需要文件上传的SharePoint列表,将该文件放在名为/Lists/{ListName}/{RecordId}/filename.ext的文件夹下的列表目录中。 p>
我如何使用fieldType实现此功能,它会在Page.IsPostBack的页面加载检查中获取FileUpload WebControl进行渲染但是没有收到文件(FileUpload.HasFile总是返回false)?
public class UploadControl : BaseFieldControl {
protected FileUpload fileupload;
protected override void CreateChildControls()
{
base.CreateChildControls();
//FIX FOR PROBLEM
Page.Form.Enctype = "multipart/form-data";
//FIX FOR PROBLEM
if (ControlMode == SPControlMode.Edit || ControlMode == SPControlMode.New || PreviousControlMode == SPControlMode.Edit)
{
fileupload = new FileUpload();
fileupload.ID = "fileUpload";
Controls.Add(fileupload);
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (fileupload != null && Page.IsPostBack)
throw new Exception("Uploaded Has File " + fileupload.HasFile);
//Always Returns False
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
EnsureChildControls();
}
public override object Value
{
get
{
EnsureChildControls();
if (ControlMode == SPControlMode.New || ControlMode == SPControlMode.Edit)
return "FileName.EXT";
return "";
}
set
{
EnsureChildControls();
var str = (String)value;
}
}
}
答案 0 :(得分:1)
我不完全确定SharePoint页面背后的代码(没有一个方便),但请确保表单标记为:
enctype='multipart/form-data'
属性,因为它是文件上传所必需的。如果不是,你可以随时做一个
Form.Enctype = "multipart/form-data"
在早期页面循环方法中。此外,请确保上传不是异步发生的,例如在更新面板中,因为我认为不允许上传。