本文整理汇总了C#中IMediaService.Save方法的典型用法代码示例。如果您正苦于以下问题:C# IMediaService.Save方法的具体用法?C# IMediaService.Save怎么用?C# IMediaService.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMediaService
的用法示例。
在下文中一共展示了IMediaService.Save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOrCreateMediaItem
/// <summary>
/// Get or Create a media folder
/// </summary>
/// <param name="mediaName"></param>
/// <param name="mediaService"></param>
/// <param name="documentType"> </param>
/// <param name="parentNodeId"></param>
/// <returns></returns>
public static IMedia GetOrCreateMediaItem(IMediaService mediaService, string documentType, int parentNodeId, string mediaName, byte[] file = null)
{
var childItems = mediaService.GetChildren(parentNodeId);
IMedia childItem = null;
var enumerable = childItems as IMedia[] ?? childItems.ToArray();
if (enumerable.Any())
{
childItem = enumerable.FirstOrDefault(i => i.Name.ToLower().Equals(mediaName.ToLower()));
}
if (childItem == null)
{
childItem = mediaService.CreateMedia(mediaName, parentNodeId, documentType);
if (file != null)
{
childItem.SetValue("umbracoFile", mediaName, new MemoryStream(file));
}
mediaService.Save(childItem);
}
return childItem;
}
示例2: RelocateFile
private void RelocateFile(IMediaService sender, IMedia mediaItem)
{
if (!mediaItem.Properties.Contains("umbracoFile"))
return;
// Get file and extension data
string file = (string)mediaItem.Properties["umbracoFile"].Value;
//string ext = mediaItem.Properties["umbracoExtension"].Value;
string parentPath = GetParentPath(sender, mediaItem);
if (!string.IsNullOrWhiteSpace(file))
{
// Website name, node path
string newpath = "/" + Path.Combine("media", parentPath, Path.GetFileName(file)).Replace('\\', '/');
if (!newpath.Equals(file, StringComparison.CurrentCultureIgnoreCase))
{
MoveFile(file, newpath);
MoveFile(AppendFileName(file, "_thumb"), AppendFileName(newpath, "_thumb"));
MoveFile(AppendFileName(file, "_big-thumb"), AppendFileName(newpath, "_big-thumb"));
// Change the path
mediaItem.Properties["umbracoFile"].Value = newpath;
if (mediaItem.Properties.Contains("localPath"))
mediaItem.Properties["localPath"].Value = newpath;
sender.Save(mediaItem);
}
}
}
示例3: MediaService_Moved
private void MediaService_Moved(IMediaService sender, MoveEventArgs<IMedia> e)
{
foreach (var mediaItem in e.MoveInfoCollection)
sender.Save(mediaItem.Entity);
}