For a project we created a library for a SharePoint site definition. This could easily be done in Visual Studio 2012/2013 by clicking Add > New Item in the Solution Explorer. Build the solution and deploy and everything is fine. Everything?

Something, a developer normally does not test is the SaveAs-dialog in any of the Office applications (like Word). When you try to use this function an navigate to the library created by the solution, you will see a dialog like this:

As you can see in this dialog, we can change the filename and click the Save-button, but we are not able to navigate in the library, when there are folders, nor do we see which documents are already in this library. Doing the same in a document library created with one of the out-of-the-box templates shows a dialog like this:

So, what is the difference between these two document libraries?

The view for the SaveAs dialog is defined in SharePoint in the library itself. So, anything in the view definitions must be different.

First, let’s have a look into the view definition for the file dialog of our custom library:

<View BaseViewID="2" Type="HTML" FileDialog="TRUE" TabularView="FALSE" DisplayName="$Resources:core,File_Dialog_View;" Hidden="TRUE" Path="filedlg.htm" ModerationType="Moderator">
  <Toolbar Type="Standard" />
  <ViewFields>
    <FieldRef Name="DocIcon"></FieldRef><FieldRef Name="BaseName"></FieldRef>
    <FieldRef Name="Editor" TextOnly="TRUE"></FieldRef>
    <FieldRef Name="Modified" TextOnly="TRUE"></FieldRef>
  </ViewFields>
  <Query>
    <OrderBy>
      <FieldRef Name="FSObjType" Key="Primary" />
      <FieldRef Name="FileLeafRef" />
    </OrderBy>
  </Query>
</View> 

 

This looks fine. Very compact, but we know these View nodes from other views we have built in SharePoint solutions.

Next let’s have a look into the same View definition for a library that was created with the out-of-the-box template:

<View BaseViewID="2" Type="HTML" FileDialog="TRUE" TabularView="FALSE" DisplayName="$Resources:core,File_Dialog_View;" Hidden="TRUE" Path="filedlg.htm" ModerationType="Moderator">
  <ViewHeader>
    <SetVar Name="FileDialog">1</SetVar>
    <HTML>
      <![CDATA[
      <table id="FileDialogViewTable" width="100%" style="cursor: default;" border="0" rules="rows" cellspacing="0" cellpadding="2">
          <tr>
  ]]>
    </HTML>
    <Fields>
      <HTML><![CDATA[<th class="ms-vh2-nofilter">]]></HTML>
      <Field />
      <HTML><![CDATA[</th>]]></HTML>
    </Fields>
    <HTML><![CDATA[</tr>]]></HTML>
  </ViewHeader>
  <ViewBody>
    <SetVar Name="FileDialog">1</SetVar>
    <IfEqual>
      <Expr1>
        <GetVar Name="AlternateStyle" />
      </Expr1>
      <Expr2>ms-alternating</Expr2>
      <Then>
        <SetVar Scope="Request" Name="AlternateStyle">
        </SetVar>
      </Then>
      <Else>
        <SetVar Scope="Request" Name="AlternateStyle">ms-alternating</SetVar>
      </Else>
    </IfEqual>
    <Switch>
      <Expr>
        <LookupColumn Name="FSObjType" />
      </Expr>
      <Case Value="1">
        <HTML>&lt;TR fileattribute=folder ID="</HTML>
      </Case>
      <Default>
        <HTML>&lt;TR fileattribute=file ID="</HTML>
      </Default>
    </Switch>
    <Field Name="EncodedAbsUrl" />
    <HTML><![CDATA[" class="]]></HTML>
    <GetVar Name="AlternateStyle" />
    <HTML><![CDATA[" onmousedown="selectrow()" onclick="selectrow()">]]></HTML>
    <Fields>
      <HTML><![CDATA[<td class="ms-vb" style="padding-left: 4px">]]></HTML>
      <FieldSwitch>
        <Expr>
          <Property Select="Type" />
        </Expr>
        <Case Value="User">
          <LookupColumn HTMLEncode="TRUE" />
        </Case>
        <Default>
          <FieldSwitch>
            <Expr>
              <Property Select="Name" />
            </Expr>
            <Case Value="CheckoutUser">
              <Field HTMLEncode="TRUE" />
            </Case>
            <Default>
              <Field />
            </Default>
          </FieldSwitch>
        </Default>
      </FieldSwitch>
      <HTML><![CDATA[</td>]]></HTML>
    </Fields>
    <HTML><![CDATA[</tr>]]></HTML>
  </ViewBody>
  <ViewFooter>
    <HTML><![CDATA[</table>]]></HTML>
  </ViewFooter>
  <ViewEmpty>
    <SetVar Name="FileDialog">1</SetVar>
    <HTML>
      <![CDATA[
      <table id="FileDialogViewTable" width="100%" style="cursor: default;" border="0" rules="rows" cellspacing="0" cellpadding="2">
          <tr>
  ]]>
    </HTML>
    <Fields>
      <Switch>
        <Expr>
          <Property Select="Name" />
        </Expr>
        <Case Value="FileLeafRef">
        </Case>
        <Default>
          <HTML><![CDATA[<th class="ms-vh2-nofilter">]]></HTML>
          <Field />
          <HTML><![CDATA[</th>]]></HTML>
        </Default>
      </Switch>
    </Fields>
    <HTML><![CDATA[</tr></table>]]></HTML>
    <HTML><![CDATA[<table width="100%" border="0" rules="rows"><tr>]]></HTML>
    <HTML><![CDATA[<td class="ms-vb">]]></HTML>
    <HTML>$Resources:core,noDocOfSpecType;</HTML>
    <HTML><![CDATA[</td></tr></table>]]></HTML>
  </ViewEmpty>
  <ViewFields>
    <FieldRef Name="DocIcon">
    </FieldRef>
    <FieldRef Name="BaseName">
    </FieldRef>
    <FieldRef Name="Editor" TextOnly="TRUE">
    </FieldRef>
    <FieldRef Name="Modified" TextOnly="TRUE">
    </FieldRef>
  </ViewFields>
  <Query>
    <OrderBy>
      <FieldRef Name="FSObjType" Key="Primary" />
      <FieldRef Name="FileLeafRef" />
    </OrderBy>
  </Query>
</View> 

 

Uups, this looks a little bit different. In this View node we have additional the nodes

  • ViewHeader
  • ViewBody
  • ViewFooter
  • ViewEmpty

When we copy exactly this View node into the schema.xml of our custom library, the SaveAs dialog works as expected. It seems, this is an issue with the template in Visual Studio 2012/2013.

Advertisements