我在使用 umbraco 用户控件时遇到了一些问题。我正在尝试开发照片库。我有一个带有媒体选择器的用户控件,在保存时我想生成所选文件夹中所有媒体文件的缩略图。到目前为止,一切都很好..
1 个文档可能包含多个照片库属性,因此要确定存储缩略图的路径,我必须执行以下操作:
'PhotoGalleryStorageFolder/{DocumentID}/{UsercontrolPropertyId}'
检索文档 ID 很简单:
_currentNodeId = int.Parse(Request.QueryString["id"]);
问题是我不知道别名,我不想在我的用户控件中硬编码它,因为它可能有更多实例..
代码:
private Int32 _currentNodeId = -1;
private Int32 _currentPhotoGalleryId = -1;
private String _value = ""; // Holds MediaPickerValue;
protected void Page_Load(object sender, EventArgs e)
{
initialize();
}
#region Initialize
private void initialize()
{
_currentNodeId = int.Parse(Request.QueryString["id"]);
/////// PROBLEM \\\\\\\\\
_currentPhotoGalleryId = -1; // How to retrieve this?!?!
\\\\\\\ PROBLEM /////////
Document d = new Document(_currentNodeId);
if (!Page.IsPostBack)
{
this.setMediaPickerValue(_value);
this.setPrevMediaPickerValue(_value);
}
else
_value = this.getMediaPickerValue();
Response.Write("_currentNodeId: " + _currentNodeId.ToString() + "<br />");
Response.Write("_value: " + _value + "<br />");
}
void Document_AfterSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
}
#endregion
#region MediaPickerValue
private String getMediaPickerValue()
{
return mediaPicker.Value;
}
private void setMediaPickerValue(String value)
{
mediaPicker.Value = value;
}
private String getPrevMediaPickerValue()
{
return prevMediaPickerValue.Value;
}
private void setPrevMediaPickerValue(String value)
{
prevMediaPickerValue.Value = value;
}
#endregion
#region OnSave
private void onSave()
{
String currentValue = this.getMediaPickerValue();
String prevValue = this.getPrevMediaPickerValue();
if (currentValue != prevValue) HttpContext.Current.Response.Write("Hergenereer thumbs.<br />");
else HttpContext.Current.Response.Write("Thumbs hoeven niet opnieuw te worden gegenereerd.<br />");
this.setPrevMediaPickerValue(currentValue);
}
#endregion
public object value
{
get
{
onSave();
return this.getMediaPickerValue();
}
set
{
Response.Write("Set triggered<br />");
String val = string.IsNullOrEmpty(value.ToString()) || value == null ? "" : value.ToString();
_value = val;
}
}
对此的任何帮助都会很棒..提前谢谢!