I'm allowing a user to upload an excel file which has a path to images. The problem is it's throwing the following error:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\gwphi_000\Desktop\test\OrderEmail.png'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.File.InternalReadAllBytes(String path, Boolean checkHost) at UploadExelFiles.Helpers.GetExcelDataFromFile.ReadExcelFile(String pathToMedia)
In IIS I have changed the app pool to Network Services and on my local testing machine that works ok, but when on the remote server it throws the error.
My code is
foreach (var item in excelList)
{
string fileName = Guid.NewGuid().ToString();
var content = contentService.CreateContent(item.Product, allEventsNode.Id, "accessorieItems");
IMediaService mediaService = ApplicationContext.Current.Services.MediaService;
var newImage = mediaService.CreateMedia($"{fileName}.jpeg", -1, "Image");
byte[] buffer = File.ReadAllBytes(Path.GetFullPath(item.ProductUrl));
MemoryStream strm = new MemoryStream(buffer);
newImage.SetValue("umbracoFile", $"{fileName}.jpeg", strm);
mediaService.Save(newImage);
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var image = umbracoHelper.Media(newImage.Id).Url;
string imagePath = image.ToString();
content.SetValue("productId", item.ProductId);
content.SetValue("productTitle", item.Product);
content.SetValue("productPrice", item.Price);
content.SetValue("productImage", imagePath);
content.SetValue("productDescription", item.ProductDescription);
contentService.SaveAndPublishWithStatus(content);
}