Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用项目web api在sitecore 6.5中创建媒体项目_C#_Sitecore_Asp.net Web Api_Sitecore6 - Fatal编程技术网

C# 如何使用项目web api在sitecore 6.5中创建媒体项目

C# 如何使用项目web api在sitecore 6.5中创建媒体项目,c#,sitecore,asp.net-web-api,sitecore6,C#,Sitecore,Asp.net Web Api,Sitecore6,我们在项目中使用Sitecore 6.5 在项目的一个站点中,用户必须能够将pdf/doc文件上载到服务器。当他上传时,这会被添加到web数据库中,因此我们必须将其传输到主数据库 我正试图通过使用Sitecore的ItemWebAPI来实现这一点 我已经研究了如何做这件事。但我不能让它工作 每当我执行请求时,我都会收到一个内部服务器错误,告诉我没有找到请求文档的布局 生成的url如下所示: {host}/-/item/v1/?name=45c87793-4b37-40c8-acbc-a3b8f2

我们在项目中使用Sitecore 6.5

在项目的一个站点中,用户必须能够将pdf/doc文件上载到服务器。当他上传时,这会被添加到web数据库中,因此我们必须将其传输到主数据库

我正试图通过使用Sitecore的ItemWebAPI来实现这一点

我已经研究了如何做这件事。但我不能让它工作

每当我执行请求时,我都会收到一个内部服务器错误,告诉我没有找到请求文档的布局

生成的url如下所示:

{host}/-/item/v1/?name=45c87793-4b37-40c8-acbc-a3b8f2b0c275&sc_itemid=653a9a07-6ea0-4e9a-8214-6bf3447096ed&sc_database=master&payload=min
据我所知,我认为url是建立正确的

使用以下url执行get请求确实有效:

{host}/-/item/v1/?sc_itemid=653a9a07-6ea0-4e9a-8214-6bf3447096ed
你知道我遗漏了什么吗

编辑:

以下是我如何称呼媒体海报的代码

var mediaPoster = new MediaPoster("http://{host}/", @"sitecore\admin", "b");

if (pdfStream != null)
     mediaPoster.PostMedia(item.Name, new Guid("{653A9A07-6EA0-4E9A-8214-6BF3447096ED}"), "master", new MemoryStream(pdfStream.ToArray()), ".pdf");

还要验证您的配置是否正确。要上载文件,您需要设置安全性

  <site name="website">
    <patch:attribute name="itemwebapi.mode">StandardSecurity</patch:attribute>
    <patch:attribute name="itemwebapi.access">ReadWrite</patch:attribute>
    <patch:attribute name="itemwebapi.allowanonymousaccess">false</patch:attribute>
  </site>
它应该是有效的,如果你仍然得到那个错误,请告诉我

更新

您知道Sitecore中的showconfig.aspx吗?您可以使用它来查看配置文件是如何被解析的。 我建议你去那里
http://HOST/sitecore/admin/showconfig.aspx
,搜索
,查看您的网站是如何设置的。所有补丁属性(模式、访问、AllowAnuMousAccess)都应该与上面的配置类似

只要您的用户是管理员,它就应该可以访问medialibrary和所有其他安全方面

我刚才想的另一点。您是否获得了适用于Sitecore版本的项Web Api模块的正确版本

1.0

Sitecore项目Web API模块v1.0.0 rev.120828已发布。
Sitecore项目Web API模块已通过Sitecore CMS 6.5.0测试 版本120706(更新-5)和CMS 6.6.0版本120918(初始版本)

1.2

Sitecore项目Web API 1.2.0版本。140128已发布。
Sitecore项目Web API模块已使用Sitecore CMS 6.6.0版本进行了测试。 131211(6.6.0更新-7)和7.1修订版。140130(7.1更新-1)


嗨,你能在你叫mp.PostMedia的地方添加代码吗?这个文件的扩展名是什么。我看到您使用了guid作为文件名,这是您想要的吗?嗨,Roberto,我在调用PostMedia函数的地方添加了代码。您可以在代码示例中看到的扩展是pdf。我打算使用guid作为文件名。我忘记安装软件包Sitecore.ItemWebApi。。。(哑巴..我知道..但我认为这是不必要的,因为检索项目起作用。)我现在安装了它,在设置了您提供给我的配置选项后,出现了另一个错误。所以我想我可以从现在开始继续。谢谢你的回答!我一直在尝试,但仍然会出错。更具体地说,错误发生在以下类中:Sitecore.ItemWebApi.Pipelines.HttpRequest.CheckMode。显然,模式设置为关闭。在我的.config文件中,我100%确定它设置为StandardSecurity。例如,您在上面给我的选项。我已设法解决上述问题。但现在我得到了一个OK状态,但通过使用postman,我可以看到实际给出的响应如下:“未授予对站点的访问权。”这很奇怪,因为我使用的是管理员用户。。我已经在媒体库本身和库中的文件夹上进行了尝试。您好。。我更新了答案以便更容易阅读。。看看那里。谢谢。是的,我知道showconfig。我用它来检查站点设置,但我们使用的是MultiItemManager而不是sites.config。所以我不得不修改里面的一切。现在一切都好了。我的网站有这些设置,我在调试时检查过。我采用了sitecore Web API模块的1.0版,因为我们有sitecore.NET 6.5.0(版本121009)。所以我认为所有这些设置都是正确的。
string HOST = @"http://HOST/";
string ParentID = "{3D6658D8-A0BF-4E75-B3E2-D050FABCF4E1}";         //Must be media library folder/item. this is the root
string mediaFileExt = ".pdf";                                       //you need to specify the extension. You can get that by the content-type returned or the way you find better.

HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://sdn.sitecore.net/upload/sdn5/modules/sitecore%20item%20web%20api/sitecore_item_web_api_developer_guide_sc65-66-usletter.pdf");
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream mediaStream = httpWebReponse.GetResponseStream();


//create a instance and inform the credentials as well the host
MediaPost mp = new MediaPost(HOST, @"sitecore\admin", "b");

//post the media!
//Important: It needs a Valid Item Name,
//                    a Valid Parent ID under Media Library,
//                    the database, the stream and the extension
mp.PostMedia("DocumentName", new Guid(ParentID), "master", mediaStream, mediaFileExt);