The object FileSaveItem is a local object to store some useful data about the file
Publikation is a pagetype that holds the assetfolder reference
Code:
My personal C# snippets archive, some EPiServer related. Also my gigs with the bands I play with.
FileSaveItem item = new FileSaveItem { Success = false }; HttpPostedFile file = Request.Files[0]; var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var blobFactory = ServiceLocator.Current.GetInstance<BlobFactory>(); //Get a new empty file data var file1 = contentRepository.GetDefault<GenericMedia>(publikation.AssetFolder); string filename = DateTime.Now.ToString("yyyy-MM-dd_HHmm") + Path.GetExtension(file.FileName); item.Filename = filename; file1.Name = filename; file1.Description = filename; var blob = blobFactory.CreateBlob(file1.BinaryDataContainer, Path.GetExtension(file.FileName)); item.FileSizeBytes = file.InputStream.Length; blob.Write(file.InputStream); file1.BinaryData = blob; item.FileRef = contentRepository.Save(file1, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
Inga kommentarer:
Skicka en kommentar