문제

나는 사용하기로 결정했 SaveBinaryDirect 방법을 업로드한 문서를 sharepoint 사이트로 인해지는 요청/파일 크기 제한 사항이 있는 클라이언트 객체 모델이다.

응용 프로그램은 두 가지를 추가하는 폴더(를 사용하여 클라이언트 객체 모델)및 그 후 업로드하는 파일과 폴더가 생성(사용하여 저장을 바이너리로 직접).

이에서 잘 작동합 내 설정 여기에.하지만 우리의 클라이언트는 사이트를 사용하면 폴더가 만들어지지만 파일을 업로드 할 부분을 반환합니다"무단 401"오류가 있습니다.

            SP.ClientContext ctx = new SP.ClientContext(siteurl);
            SP.Web currentWeb = ctx.Web;
            //Pass user details from config (That has owner permissions)
            ctx.Credentials = new NetworkCredential(username, password, domain);   
            //create folder method (checks if the folder exists and creates using Client Object Model)
            CreateFolder(ctx,libraryUrl,folderName)

            //Save Binary Direct Method
            string fileUrl = "/"+ libraryname + "/" + folderName + "/" + fileName;
            using (data)
            {
                //upload by passing the context, file url, file data stream, 
                //set overwrite to true
                SP.File.SaveBinaryDirect(ctx, fileUrl,data, true);
            }

이 나를 생각하게 두 가지 중 하나

  1. 가 있는 설정을 변경할 필요가에서 공유 또는 웹 서버에서 관련하여 승인/인증이 있습니다.
  2. 이 방법을 적용하겠 네트워크 자격은 잘못된 것입니다.그것은 단지 않는 클라이언트에 대한 객체 모델은 아니지만 저는 이진다.

내가 알고 있는 우리가 사용할 수 있는 클라이언트 객체 모델,그리고 우리는 할 필요가 있습니다 또 다른 버전 경우 해당되지 구성/설치 문제를 해결합니다.

누구는 더 많은 경험을 가진 이에 대한 몇 가지 아이디어가 있는 왜 그 일을 하는 것일까요?

도움이 되었습니까?

해결책

SharePoint 2013을 사용하는 경우 SaveBinaryDirect를 사용할 수 없으면 클레임 인증에서는 작동하지 않습니다.SaveBinaryDirect가 만든 호출에는 필요한 권한 부여 쿠키가 포함되어 있지 않습니다.세부 사항은이 블로그 게시물에 대한 의견에서 논의됩니다 : Office 365 및 SharePoint 온라인으로 활성 인증을 수행하는 방법

업데이트 (2016 년 7 월 2 일) :

James Love에 의한 의견을 본 후에 나는 이것을 또 다른 모습으로 보았습니다.나는 바뀌지 만 내 테스트는 SaveBinaryDirect가 SharePoint 2013 및 SharePoint Online을 사용하고 있음을 나타냅니다.

여기에 사용 된 코드가 있습니다 :

// var context = new ClientContext("http://intranet.wingtip.com/sites/demo/");
// context.Credentials = System.Net.CredentialCache.DefaultCredentials;

var context = new ClientContext("https://robwindsor2.sharepoint.com/sites/demo/");
context.Credentials = new SharePointOnlineCredentials(loginName, securePassword);

var web = context.Web;
var lib = web.Lists.GetByTitle("Documents");

context.Load(lib);
context.Load(lib.RootFolder);
context.ExecuteQuery();

var fileName = "Test.docx";
var filePath = @"C:\Users\robwindsor\Desktop\" + fileName;
using (var fs = new FileStream(filePath, FileMode.Open))
{
    Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, lib.RootFolder.ServerRelativeUrl + "/" + fileName, fs, true);
}

var query = new CamlQuery();
query.ViewXml = "<View></View>";
var files = lib.GetItems(query);

context.Load(files, c => c.Include(f => f.File));
context.ExecuteQuery();

foreach(ListItem item in files)
{
    Console.WriteLine(item.File.Name);
}

Console.WriteLine("Done");        
.

다른 팁

시도 :

FileCreationInformation fci = new FileCreationInformation();

fci.Content = newFile.Bytes;

fci.Url = sourceFile.Url;

fci.Overwrite = true;

Microsoft.SharePoint.Client.File replacedFile = list.RootFolder.Files.Add(fci);

context.Load(replacedFile);

context.ExecuteQuery();
.

클라이언트 객체 모델을 사용하여 파일 시스템에서 SharePoint 2010에서 파일을 업로드 할 수 있습니다.

승인되지 않은 401을받는 경우 올바른 자격 증명을 제공하고 대상 SharePoint 문서 라이브러리 폴더의 상대 URL을 올바르게 제공하고 있는지 확인하십시오.

ClientContext ctx = new ClientContext(Siteurl);
ctx.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
var sourceFilePath = @"C:\test\test.xlsx";
var targetUrl = "/Shared%20Documents";
var targetFileUrl = String.Format("{0}/{1}", targetUrl, Path.GetFileName(sourceFilePath));
var fs = new FileStream(sourceFilePath, FileMode.Open);
Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, targetFileUrl, fs, true);
var uploadedFile = ctx.Web.GetFileByServerRelativeUrl(targetFileUrl);
var listItem = uploadedFile.ListItemAllFields;
listItem.Update();
ctx.ExecuteQuery();
.

다음을 추가해야합니다.

ctx.RequestTimeout = 3600000;
.

동일한 문제가 발생했지만 합법적인지 모르지만 해결 방법을 찾았습니다.

 System.Net.WebClient webClient = new System.Net.WebClient();

 System.Uri uri = new Uri(url); //Create a uri object with the file name but without extension

 webClient.Credentials = new NetworkCredential(username,password,domain);        //Network credentials to connect with the sharepoint server

 webClient.UploadFile(uri, "PUT", pFilePath);     //Upload File will push the file to the server
.

TLDR:당신을 사용할 필요가 서버 상대 URL 이하더라도,컨텍스트를 포함한 사이트 정보입니다.

나는 이와 동일한 문제 및 해결을 사용하여 Fiddler.사용하면 클라이언트 객체 모델을 만들고,컨텍스트가 사이트와 경로,즉"https://server/sites/siteName"다음

var docs = web.Lists.GetByTitle(documentLibraryName);
SP.File uploadFile = docs.RootFolder.Files.Add(newFile);
context.Load(uploadFile);
context.ExecuteQuery();

이 게시물을 https://<server>/sites/<siteName>/_vti_bin/client.svc/ProcessQuery 경로와 파일이름(및 컨텐츠)에 포함되었는 XML 의 CSOM.

지금 SP.File.SaveBinaryDirect 서명은 SaveBinaryDirect(ClientContext context, string serverRelativeUrl, Stream stream, bool overwriteIfExists) -하지만 요청 SaveBinaryDirect(context, "/<library>/<folder>/filename", stream, true) 실패와 함께 401 오류가 있습니다.보 Fiddler,그리고 여기에 요청을 만들어:

PUT https://<server>/<library>/<filename>

도 컨텍스트 이 포함됩 사이트서,당신은 그것을 전체 경로 에서 서버는 루트입니다.성공적인 통화

SaveBinaryDirect(context, "/sites/<sitename>/<library>/<folder>/filename", stream, true)

그 결과에 넣어 정확한 위치.매개변수 serverRelativeUrl 니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top