内容简介:翻译自:https://stackoverflow.com/questions/13602717/cannot-upload-image-to-a-sharepoint-list
这是我的ListView:
Image http://i47.tinypic.com/x5z2v7.jpg .
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;
}
}
您可以使用以下方法将文件直接从文件上载添加到特定Web,然后将文件路径添加到列表中,如下例所示,
SPContext.Current.Web.Files.Add(String.Concat(SPContext.Current.Web.Site.RootWeb.Url, path), stream, true);
path是图像的相对路径.在用户案例文件名中.
stream可以在文件上传控件中使用FileUpload.FileContent
然后将此路径添加到列表中,如下所示.
listItem["Image"] = path;
这适用于所有浏览器.
翻译自:https://stackoverflow.com/questions/13602717/cannot-upload-image-to-a-sharepoint-list
以上所述就是小编给大家介绍的《c# – 无法将图像上载到SharePoint列表》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Programming in Haskell
Graham Hutton / Cambridge University Press / 2007-1-18 / GBP 34.99
Haskell is one of the leading languages for teaching functional programming, enabling students to write simpler and cleaner code, and to learn how to structure and reason about programs. This introduc......一起来看看 《Programming in Haskell》 这本书的介绍吧!