The path you're getting is the external URL. You have to get the local disk path, if you have it stored on the disk that is. But a safer way is to just load the data through the API, then the file could be stored anywhere.
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); MediaData media; if (contentLoader.TryGet(excelFileContentReference, out media)) { using (var stream = media.BinaryData.OpenRead()) { using (var package = new ExcelPackage(stream)) { } } }
Hi,
I am using EPiserver CMS 10 hosted in Azure. I have a block where I have created content reference property for selecting Excel file uploaded in blob storage. This excel file has worksheet which has some data. I have one more string property in the block. When user creates a block, I want to read the selected file and put the worksheet data in this string property during publish event.On publish I have written Initialization module, where I want to read the selected file by editor and put the values in String property.
I am using EPPlus openxml for file read.
The issue I am getting is, I am not able to read the selected excel file. I tried using
var path = EPiServer.Web.Routing.UrlResolver.Current.GetUrl(ExcelFileContentReference);
if (ExcelFileContentReference!= null)
{
templateFile = new FileInfo(path);
return templateFile;
}
ExcelPackage xlPackage = new ExcelPackage(templateFile)
ExcelWorksheet workSheet = xlPackage.Workbook.Worksheets["Json"];
path comes like 'globalasset/abc.xlsx' and it gives workSheet empty.
Am I on right path? How can I read file from blob storage.
Thanks & Regards,
Sanket Mahimkar