将文件从Webpart上传到文档库,并将路径保存到共享点列表 [英] upload file from webpart to document library and save path to sharepoint list

查看:87
本文介绍了将文件从Webpart上传到文档库,并将路径保存到共享点列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是共享点的新手,我创建了一个Web部件,该Web部件的表单输入在提交时被保存在共享点列表中.我的要求是在Web部件中具有上载文件功能,以帮助用户上载文档库中的附件并保存路径 提交时共享点列表中的相应列表项.有人可以帮我吗?

I am new to share point, I created a web-part which has a form inputs that gets saved in share point list on submit. My requirement is to have an upload file feature in web part that helps user to upload attachments in document library and saves the path with respective list item in share point list on submit. Can anybody help me with that?

预先感谢!

推荐答案

示例代码供您参考.

网页部分 前端:

<div>
    <asp:FileUpload ID="file_Upload" runat="server" />
    <br />
    <asp:Button ID="btnSubmit" OnClick="btnSubmit_Click" runat="server" Text="Button" />
</div>

后端 c#:

protected void btnSubmit_Click(object sender, EventArgs e)
        {
            SPList list=SPContext.Current.Web.Lists["Test"];
            Stream fStream = file_Upload.PostedFile.InputStream;  
            byte[] contents = new byte[fStream.Length];  
            fStream.Read(contents, 0, (int)fStream.Length);  
            fStream.Close();

            SPListItem item = list.GetItemById(1);
            item.Attachments.Add(file_Upload.PostedFile.FileName, contents);
            item.Update();
        }

最好的问候,

Lee


这篇关于将文件从Webpart上传到文档库,并将路径保存到共享点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆