Try our conversational search powered by Generative AI!

How to achieve description of image stored in the file manager of Episerver

Vote:
 

Hi,

I have a problem achieving the meta data from files stored in the file manager in Episerver.

There is a function in our solution that is supposed to fix this, but often it doesn't work.

I use the function below to get description information from the files, but very often it returns nothing.

Anyone have a better/safer method to get the description information stored on files in Episerver - File manager?

 

Caller:

String imagedescription = GetMetaDataFromImageURL(CurrentPage["MainIntroPicture"].ToString(), "Description");

 

Funcition:

protected static string GetMetaDataFromImageURL(string imageurl, string metainstance)
{

string s = string.Empty;
if (imageurl!=null)
{
UnifiedFile uf = HostingEnvironment.VirtualPathProvider.GetFile(imageurl) as UnifiedFile;
if (uf != null)
{
if (uf.Summary.Dictionary[metainstance] != null)
s = uf.Summary.Dictionary[metainstance].ToString();
}
}
return s;
}

#65900
Feb 13, 2013 17:08
Vote:
 

Just tried your code, it works.

I'm guessing your MainIntroPicture property is of type "URL to image"? (which will render a relative path to the file, like "/Global/Images/mypicture.jpg")

However, you shouldn't do CurrentPage["MainIntroPicture"].ToString(), since it will throw a NULL reference exception if the property has no value set. Do GetMetaDataFromImageURL(CurrentPage["MainIntroPicture"] as string, "Description") instead, or CurrentPage.MainIntroPicture if you're using PTB.

 

#65911
Feb 13, 2013 22:09
Vote:
 

Good tip Arild, I will change that.

I found the error. They say you can't see the forrest because of all the trees.

Kind of the same here. You can't see the function-error because of all the code.

I was missing Server.UrlDecode on CurrentPage["MainIntroPicture"].

Correct code is:

String imagedescription = GetMetaDataFromImageURL(Server.UrlDecode(CurrentPage["MainIntroPicture"] as String), "Description");

 

#65936
Feb 15, 2013 10:21
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.