Pau*_*tos 2 c# sitecore sitecore7.5
使用Sitecore 7.5,我试图在媒体库中存储几个html文件.然后在我的子布局代码隐藏中,我试图抓住那些html文件的内部内容.
当我在服务器上存储html文件时,我有这个工作.我会使用"上传为文件"将文件上传到媒体库,然后使用以下代码阅读内容:
string filename = htmlMediaItem.Fields["File Path"].ToString();
string path = Server.MapPath(filename);
string content = System.IO.File.ReadAllText(path);
Run Code Online (Sandbox Code Playgroud)
但是我现在想要这样做而不将文件存储在服务器上,而只是将它们放在媒体库中.无论如何我能做到吗?
到目前为止,我一直很难找到有关该主题的信息.
谢谢.
根据我的理解,您想要阅读存储在媒体库中的html文件的内容.
Sitecore.Data.Items.Item sampleItem = Sitecore.Context.Database.GetItem("/sitecore/media library/Files/yourhtmlfile");
Sitecore.Data.Items.Item sampleMedia = new Sitecore.Data.Items.MediaItem(sampleItem);
using(var reader = new StreamReader(MediaManager.GetMedia(sampleMedia).GetStream().Stream))
{
string text = reader.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4391 次 |
最近记录: |