Upload files programmatically, not available for editors



I know how to upload files programmatically with the BlobFactory.

This is my code:

var file = _contentRepository.Service.GetDefault<GenericMedia>(SiteDefinition.Current.GlobalAssetsRoot);
file.Name = createMessageFileData.FileName;

var fileExtension = createMessageFileData.FileName.Split('.');
var blob = _blobFactory.Service.CreateBlob(file.BinaryDataContainer, fileExtension[fileExtension.Length - 1]);
using (var s = blob.OpenWrite())
using (var sw = new StreamWriter(s))
file.BinaryData = blob;
return _contentRepository.Service.Save(file, SaveAction.Publish);

At the first line, I specify where I want to store the file.

Is there any way to specify a custom place to store the files unavailable for editors?

// Anders

Mar 26, 2014 10:39


Mar 27, 2014 15:27

Hi Anders,

Do you mean you want to upload the files to a folder that the Editors cannot access?


Mar 27, 2014 16:52

Yes. That's correct.

I want to use the Blob Storage to store files, but unavailable for editors.

Edited, Mar 28, 2014 7:47

Can you upload to folder that has restricted access rights to it?

Mar 28, 2014 7:54

Well... That would work. But what I really want is to upload files outside of EPiServer, but I want to use the Blob Storage since it's easy to work with and I don't want to waste time creating my own logic to upload files to the webserver.

If this isn't possible I guess it's easier to create my own logic and it will also be easier to test(?).

Mar 28, 2014 8:01

Then I might use restricted folder for that - as "outside" of EPiServer using EPiServer blob storage as "proxy" is interesting case :)

If that's not a EPiServer site underneath - take care of licensing issues..

Mar 28, 2014 10:49

Ok, thanks for answering. Yes, it is indeed an interesting case. Maybe it's possible to use virtual paths instead?

FYI, there is an EPiServer site underneath. I don't understand what you mean "- take care of licensing issues..".

Thanks nontheless, Valdis. :)

Mar 28, 2014 12:09

I mean case when you would use just EPiServer empty site to upload files to server :)

Mar 28, 2014 13:07

Maybe not best practice... But you could create your own ContentFolder programmatically under root, and mess around with that. Maybe there's a better way to do it though. Haven't worked that much with this yet.

Another tip, to get Filenames, extension etc you can use the class "Path", it has some nice static methods.. :)


var _contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.IContentRepository>();
        var test = _contentRepository.GetDefault<ContentFolder>(ContentReference.RootPage);
        test.Name = "Test";
        _contentRepository.Save(test, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);


Mar 28, 2014 15:18

One way is to configure your system to have two blob providers (e.g. FileBlobProvider) with two different physical paths, the one marked as default is the one that will be used from UI etc. You can then programatically save your "hidden" files to the non-default provider by calling GetProvider in BlobFactory.

Mar 28, 2014 21:20

Thanks, Johan.

This is exactly what I want. I will try it out and post my results here when I'm finished.

Edited, Mar 31, 2014 8:40

Tip: You can specify a location in the FileBlobProvider constructor:

  var provider = new FileBlobProvider("c:\\mycustomlocation");


Mar 31, 2014 9:21
Oct 27, 2014 4:42

Here's the code you need to change:

            var file1 = contentRepository..GetDefault<GenericMedia>(SiteDefinition.Current.GlobalAssetsRoot);

You're setting the GlobalAssetsRoots as the parent folder. Change it to current page instead.



Oct 27, 2014 8:09
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.