我正在使用 Visual WebPart,我想将图像从 FileUpload 控件上传到 SharePoint 列表。这是我正在使用的代码,但我无法让它工作,(标题、prodnum、颜色等都在工作,但不是图像)。我还安装了SparQube。
protected void Button_Save_Click(object sender, EventArgs e)
{
SPSite currentSite = SPContext.Current.Site;
SPList myList = currentSite.RootWeb.Lists.TryGetList("SharePointDatabase");
try
{
if (myList != null && FileUpload_Pic.PostedFile != null && FileUpload_Pic.HasFile)
{
SPListItem listItem = myList.Items.Add();
listItem["Title"] = TextBox_Name.Text;
listItem["ProductNumber"] = TextBox_ProdNum.Text;
listItem["Color"] = TextBox_Color.Text;
listItem["ListPrice"] = TextBox_ListPrice.Text;
listItem["MoreInformation"] = TextBox_MoreInfo.Text;
string fileName = Path.GetFileName(FileUpload_Pic.PostedFile.FileName);
listItem["Image"] = fileName;
listItem.Update();
TextBox_Search.Text = string.Empty;
TextBox_Name.Text = string.Empty;
TextBox_MoreInfo.Text = string.Empty;
TextBox_ProdNum.Text = string.Empty;
TextBox_Color.Text = string.Empty;
TextBox_ListPrice.Text = string.Empty;
Label_Exception.Text = "Saved to Database list.";
Dispose();
}
}
catch (Exception x)
{
Label_Exception.Text = x.Message;
}
}