November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Try use the new way for virtual path providers instead with the VirtualPathRegistrationHandler
http://world.episerver.com/documentation/Class-library/?documentId=cms/8/E17C8338
Get this class from ioc by ServiceLocator and use the RegisteredVirtualPathProviders property to get your provider and settings.
I hope that gives you better responses :)
Thanks a ton for the reply @Daniel. This at least gives me a direction to dig forward. I actually have a weird requirement. The company's got a legacy software that performs a site migration to an EPiServer CMS site through the use of web services. As EPi has moved to Service API from webservices, my scene has become more complicated. On top of that, I don't have access to that software source code. All I'm doing is playing with the webservices to insert assets into EPi. At the moment, all I need is to push the assets (images and files), which I have in my database, to the EPi library through the use of VPP.
Thank you for your answer, I'll have a look at new way as you suggested.
Bikram.
Couldn't get much out of that article. Could you please provide me with some code reference?? Thanks in advance.
Bikram.
Ok for images and files and Episerver 8 you should actually no longer use vpp. Vpp are still used in 7.5+ but not for assets like images and files etc. From 7.5 and up all images and files etc are stored as any other content. So you can store files now in a similar way that you earlier created content.
1. Create your media content types that you want to use.
using System; using System.ComponentModel.DataAnnotations; using EPiServer.Core; using EPiServer.DataAbstraction; using EPiServer.DataAnnotations; using EPiServer.Framework.DataAnnotations; namespace MyEpiserverSite.Models.Media { [ContentType(DisplayName = "GenericMedia", GUID = "89761dbb-bf22-4cee-93c7-9d661d75cad8", Description = "Used for generic file types such as Word or PDF documents.")] [MediaDescriptor(ExtensionString = "pdf,doc,docx")] public class GenericMedia : MediaData { [CultureSpecific] [Editable(true)] [Display( Name = "Description", Description = "Add a description of the content.", GroupName = SystemTabNames.Content, Order = 1)] public virtual String Description { get; set; } } }
2. Get your file from database and store it as one of the media types above
public void Uploading_a_media_from_extension() { var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>(); var mediaDataResolver = ServiceLocator.Current.GetInstance<ContentMediaResolver>(); var blobFactory = ServiceLocator.Current.GetInstance<BlobFactory>(); //Get a suitable MediaData type from extension var mediaType = mediaDataResolver.GetFirstMatching(".txt"); var contentType = contentTypeRepository.Load(mediaType); //Get a new empty file data var media = contentRepository.GetDefault<MediaData>(SiteDefinition.Current.GlobalAssetsRoot, contentType.ID); media.Name = "Readme.txt"; //Create a blob in the binary container var blob = blobFactory.CreateBlob(media.BinaryDataContainer, ".txt"); using (var s = blob.OpenWrite()) { StreamWriter w = new StreamWriter(s); w.WriteLine("Hello world"); w.Flush(); } //Assign to file and publish changes media.BinaryData = blob; var file1ID = contentRepository.Save(media, SaveAction.Publish); }
Alternatively use the new rest api to insert media if you don't have access to the source of the new site. Code example below
using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://mysite.com/"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var content = new MultipartFormDataContent(); var filestream = new FileStream(path, FileMode.Open); content.Add(new StreamContent(filestream), "file", "Media.xml"); var response = client.PostAsync("/episerverapi/commerce/import/assets", content).Result; if (response.StatusCode == HttpStatusCode.OK) { var returnString = response.Content.ReadAsStringAsync().Result; returnString = returnString.Replace("\"", ""); Guid taskId = Guid.Empty; Guid.TryParse(returnString, out taskId); } }using an xml structure to describe the asset to import similar to
... <MediaType name="pdf"> <ContentFolderUri>MyType/Path</Name> <ContentType>Customer.Website.ContentTypes.PdfData, Customer.Website</ContentType> <ContentProperty> <Name>Author</Name> <Type>String</Type> </ContentProperty> <ContentProperty> <Name>CopyrightYear</Name> <Type>Int</Type> </ContentProperty> </MediaType> ...
Read more about that here
You are a legend mate. Thank you so much. I will try to make necessary adjustments to accomodate the changes. Thanks for baring.
CHeers, Bikram.
Hi,
I'm using a legacy system to move content across to a EPiServer CMS 8. These are my configuration to register a virtual path:
When I try to access provider with this code:
var provider = VirtualPathHandler.GetProvider("ProtectedModules") as VirtualPathNonUnifiedProvider;
(Gives /EPISERVER/ as virtualPathroot and is mapped correctly with physical path.)
I get full details of the provider, but as I try to do this operation:
var isVpp = VirtualPathHandler.Instance.IsVirtualPath(provider.virtualPathRoot); //returns false
foreach (var Map in VirtualPathHandler.Instance.NameToVirtualPathMapping) //returns count 0
What am I doing wrong. Any help is much appreciated. Thanks in advance.