Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.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# 如何将媒体库映像从sitecore下载到本地文件夹_C#_Sitecore_Sitecore6 - Fatal编程技术网

C# 如何将媒体库映像从sitecore下载到本地文件夹

C# 如何将媒体库映像从sitecore下载到本地文件夹,c#,sitecore,sitecore6,C#,Sitecore,Sitecore6,我尝试了这段代码,但没有使用语句 var database = Sitecore.Configuration.Factory.GetDatabase("master"); var images = database.SelectItems("/sitecore/media library/Corsair/Home Page/*"); foreach (var image in images) { var mediaItem = (MediaItem)image;

我尝试了这段代码,但没有使用语句

var database = Sitecore.Configuration.Factory.GetDatabase("master");
var images = database.SelectItems("/sitecore/media library/Corsair/Home Page/*");
foreach (var image in images)
     {
       var mediaItem = (MediaItem)image;
       var media = MediaManager.GetMedia(mediaItem);
       var stream = media.GetStream();
       using (var targetStream = File.OpenWrite(Path.Combine(@"F:\folder", image.Name + ".jpeg" )))
       {
           stream.CopyTo(targetStream);
           targetStream.Flush();
       }
     } 

这是一个适合我的例子:

//button to trigger event on front end
<asp:Button ID="myButton" Text="Export Images" OnClick="ExportMedia" runat="server" />

}

来自Goose的答案相当有效,但如果文件夹中有大量图像(200+),则需要使用Sitecore快速查询

只需在SelectItems查询的开头添加“fast:”即可,使该行看起来像:

var images = database.SelectItems("fast:/sitecore/media library/Images/Branches/descendant::*[@@templatekey='jpeg']");

“不工作”是什么意思?任何异常?它不能从“使用”语句中工作…我们无法在sitecore中查看错误…日志文件中没有任何内容?你怎么知道“使用”不起作用?运行IIS进程的用户是否具有对
f:\folder
的写入权限?images变量包含图像列表,当尝试使用OpenWrite()方法将这些图像写入本地文件夹时,我没有成功
var images = database.SelectItems("fast:/sitecore/media library/Images/Branches/descendant::*[@@templatekey='jpeg']");