Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > GetFileUrl in custom webpart datagrid View modes: 
User avatar
Member
Member
Jimmy - 4/3/2012 12:03:39 AM
   
GetFileUrl in custom webpart datagrid
Hi

I have a datagrid in a custom webpart and am not able to use GetFileUrl() to retrieve a flyer uploaded to the document type.

Here is the relevant portion of the code:

<asp:GridView runat="server" ID="gvPackages" AutoGenerateColumns="false" AllowPaging="true"
ShowHeader="false" PageSize="15" BorderStyle="None" OnPageIndexChanging="gvPackages_PageIndexChanging">
<PagerStyle BorderStyle="None" BorderWidth="0" CssClass="pager" />
<PagerSettings Mode="NumericFirstLast" />
<Columns>
<asp:TemplateField ItemStyle-BorderStyle="None">
<ItemTemplate>
<div class="package">
<div class="left">
<span class="homeName">
<%# Eval("Estate") %></span>
<div class="houseSpecs">
<span class="bed">
<%# Eval("Bed") %></span> <span class="bath">
<%# Eval("Bath") %></span> <span class="car">
<%# Eval("Car") %></span>
</div>
<br />
<div class="inner">
<img class="homeThumb" align="left" src="<%# CMS.GlobalHelper.UrlHelper.RemoveQuery(Eval("Image").ToString()) %>?maxsidesize=100&ext=.jpg"
width="100" height="63" />
<span class="address">
<%# Eval("Address") %>,<br />
<i>
<%# Eval("Suburb") %></i>,
<%# Eval("State") %>,
<%# Eval("Postcode") %></span><br />
<strong>Block Size:
<%# Eval("BlockSize") %>m²</strong>
</div>
</div>
<div class="right">
<span class="packagePrice">Fixed Price: <span class="price">$<%# Eval("Price") %></span></span><br />
<span class="approved">Approved Property</span><br />
<span class="profileBtn"><a target="_blank" href='<%# GetFileUrl("PackageFlyer") %>' title="View Package PDF">
View Flyer »</a></span>
</div>
<div class="clear">
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


When I use the code above I get the following error:

[Error loading the WebPart '']
d:\web\www.metricon.com.au\cms.net4\CMSWebParts\MetInvest\SearchHomeFHB.ascx(311): error CS0103: The name 'GetFileUrl' does not exist in the current context

Any ideas?

Thanks
James

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 4/8/2012 4:01:18 AM
   
RE:GetFileUrl in custom webpart datagrid
Hi,

here is a solution from e-mail communication.

You need to differentiate between document guid and attachment guid.

In this case, the field stores the file GUID of the image. To get URL of the attachment, you need to create an Url in the following format:

<domain>/getattachment/<file GUID>/<filename><extension>

To get such a Url, you can use the following method:

URLHelper.ResolveUrl(AttachmentManager.GetAttachmentUrl(attachmentGuid, fileName));

Please keep in mind that the fileName can be any string value.

For example, you can create a custom method in the code behind of the custom web part that would use the aforementioned method to get the attachment Url and then, you can call this method from the GridView's template.

More information can be found here:
Linking pages and files

Example of URL:

href='<%# "http://my.domain.com/getattachment/" + Eval("ImageGuidField") + "/FileName.aspx" %>'

Best regards,
Ivana Tomanickova