fileCreationInformation

fileCreationInformation

本文介绍了使用c#.net代码在sharepoint站点上载documnet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i想使用c#.net在sharepoint 2010网站上传文档我使用下面的代码,但我不明白参数 byte [] documentStream。





- 所以哪个值传递参数byte [] documentStream有什么想法帮助我。



public void UploadDocument(string siteURL,string documentListName,string documentListURL,string documentName, byte [] documentStream

{

尝试

{

使用(ClientContext clientContext = new ClientContext(siteURL))

{



//获取文档列表

Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle( documentListName);



var fileCreationInformation = new FileCreationInformation();

//分配给内容byte []即documentStream



fileCreationInformation.Content = documentStream;

//允许owerwrite of document



fileCreationInformation.Overwrite = true;

//上传网址



fileCreationInformation.Url = siteURL + /+ documentListURL +/+ documentName;



Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(

fileCreationInformation);



//更新名称为DocType的字段的元数据

uploadFile.ListItemAllFields [DocType ] =收藏夹;



uploadFile.ListItemAllFields.Update();

clientContext.ExecuteQuery();



}

}

catch(例外情况)

{

}

终于

{

}



}





- 我使用此代码,但它提供的错误参数内容不为空。

- 我尝试谷歌搜索但我没有得到最后一个参数的确切含义。



-如果想知道哪个参数传递方法请帮帮我。



谢谢。



i wan to upload the document on sharepoint 2010 site using c#.net i use below code but i not understand the parameter byte[] documentStream.


-so which value pass in parameter byte[] documentStream any idea about this help me.

public void UploadDocument(string siteURL, string documentListName, string documentListURL, string documentName, byte[] documentStream)
{
try
{
using (ClientContext clientContext = new ClientContext(siteURL))
{

//Get Document List
Microsoft.SharePoint.Client.List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);

var fileCreationInformation = new FileCreationInformation();
//Assign to content byte[] i.e. documentStream

fileCreationInformation.Content = documentStream;
//Allow owerwrite of document

fileCreationInformation.Overwrite = true;
//Upload URL

fileCreationInformation.Url = siteURL + "/" + documentListURL + "/" + documentName;

Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
fileCreationInformation);

//Update the metadata for a field having name "DocType"
uploadFile.ListItemAllFields["DocType"] = "Favourites";

uploadFile.ListItemAllFields.Update();
clientContext.ExecuteQuery();

}
}
catch (Exception ex)
{
}
finally
{
}

}


- i use this code but it's give error parameter content not null.
- i try googling but i not get exactly meaning of last parameter.

-so any idea about which parameter pass in method please help me.

Thank you.

推荐答案

try
            {
                string[] domainUserName = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[Constants.KeyDomainUserName]).Split('\\');
                string password = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[Constants.KeyPassword]);
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(domainUserName[1], password, domainUserName[0]);
                using (ClientContext clientContext = new ClientContext(spSiteUrl))
                {
                    clientContext.Credentials = credentials;
                    Web oWeb = clientContext.Web;
                    clientContext.Load(
                        oWeb,
                        website => website.Title);
                    clientContext.ExecuteQuery();

                    Microsoft.SharePoint.Client.File uploadFile = UploadFileToLibrary(file, fileName, ref fileRelativeUrl, overwriteFlag, clientContext);
                    ListItem item = uploadFile.ListItemAllFields;
                    item["Title"] = title;  //Set the metadata
                    item.Update();
                    clientContext.ExecuteQuery();
                }
            }


这篇关于使用c#.net代码在sharepoint站点上载documnet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:20