When you have a custom field on a SharePoint page's properties (of image type) it can be necessary to simply get the image's URL rather than dealing with an image object. We can access the image URL (as a string) by using the following method.
var image = (ImageFieldValue)SPContext.Current.File.Item["ImageFieldName"];
if (image != null)
{
string imageUrl = image.ImageUrl;
}
You can also access other fields of simple types (such as text) by using the following code:
var myTextField = (string)SPContext.Current.File.Item["TextFieldName"];
No comments:
Post a Comment