0

Problem: trying to get an image out of azure fileshare for manipulation. I need to read the file as an Drawing.Image for manipulation. I cannot create a valid FileInfo object or Image using uncpath (which I need to do in order to use over IIS)

Current Setup: Attach a virtual directory called Photos in IIS website pointing to UNCPath of the Azure file share (e.g. \myshare.file.core.windows.net\sharename\pathtoimages) This works as http://example.com/photos/img.jpg so I know it is not a permissions or authentication issue.

For some reason though I cannot get a reference to File.

var imgpath = Path.Combine(Server.MapPath("~/Photos"),"img.jpg") \\resolves as \\myshare.file.core.windows.net\sharename\pathtoimages\img.jpg var fi = new FileInto(imgpath); if(fi.exists) //this returns false 100% of the time var img = System.Drawing.Image.FromFile(fi.FullName);

The problem is that the file is never found to exist, even though I cant take that path and put it in an explorer window and return the img.jpg 100% of the time.

Does anyone have any idea why this would not be working? Do I need to be using CloudFileShare object to just get a read of a file I know is there?

macm
  • 544
  • 7
  • 21
  • A couple of points. Do you use user impersonation in your web-app? Also, try to read the file, even a couple of bytes. Sometimes fileinfo.exists has weird behaviors. Do you get an exception? – Fabrizio Accatino Apr 05 '18 at 06:17
  • Trying File.ReadAllBytes led me to a different error of username/pass not authenticated type error which was indeed the issue. This kind of makes sense since server.mappath is now using the UNC which really doesn't have anything to do with the virtual dir. This led me to this other guys problem and the solution here resulted in joy. https://stackoverflow.com/questions/582988/can-you-explain-why-directoryinfo-getfiles-produces-this-ioexception Thanks for the suggestion Fabrizio. – macm Apr 05 '18 at 15:42

1 Answers1

0

It turns out the issue is that I needed to wrap my code in an impersonation of the azure file share userid since the virtual directory is not really in play at all at this point.

using (new impersonation("UserName","azure","azure pass"))
{
//my IO.File code
}

I used this guys impersonation script found here. Can you explain why DirectoryInfo.GetFiles produces this IOException?

macm
  • 544
  • 7
  • 21