Syntax to declare a hyperlink field value (both Url and Description)

820 views Asked by At

I am trying to pre-populate my SharePoint list using its List Instance in SharePoint hosted app with default data. And it seems to work for the below code.

<ListInstance ...>
 <Data>
   <Rows>
     <Row>
       <Field Name="URL">http://google.com, Project Link</Field>
     </Row>
   </Rows>
 </Data>

But when i try to add the URL from list in my app it is not working.

<ListInstance ...>
     <Data>
       <Rows>
         <Row>
           <Field Name="URL">~appWebUrl/Lists/SiteImages/image.png, Project Link</Field>
         </Row>
       </Rows>
     </Data>

What is the syntax for this?

2

There are 2 answers

1
vk_muse On

I don't believe it is possible to use tokens like ~appWebUrl in xml list instance definition. I suggest just to put relative url, e.g.

<Field Name="URL">/Lists/SiteImages/image.png, Project Link</Field>
0
Gautam Sheth On

To set url field of the current web you can use the ~site. If you want it to be that of the parent site collection then use ~sitecollection

Modify your code as below:

<Field Name="URL">~site/Lists/SiteImages/image.png, Project Link</Field>

If the url is there in the parent site collection, use it as below:

<Field Name="URL">~sitecollection/Lists/SiteImages/image.png, Project Link</Field>

Reference - URL and tokens in SharePoint