1

The problem:

I want to open an excel document automatically from a custom aspx page in the layouts folder (sharepoint 2010) which refers to a document in a document library. The "DocumentUrl" is replaced automaticly with the correct url and the excel opens. But what's strange is that the page keeps reloading and thus also opening the excel document. Anyone who knows what the problem might be?

The code:

<a id="openExcelCreate" href="<%= DocumentUrl %>" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','1','SharePoint.OpenDocuments','','','','1','0','0','0x7fffffffffffffff','','')">Download File</a>
<script type="text/javascript">
  document.getElementById("openExcelCreate").click();
</script>

Updates: I've tried adding "evt.preventDefault();" to the onclick event and the page doesn't reload anymore, but then we have some troubles with saving the excel document... all kind of conflicts (file locked, ...)

  • Could you please show us the code for DispEx? – user2536 Nov 15 '12 at 13:44
  • It's used in core.js from sharepoint, so default code... – Ruben Herman Nov 15 '12 at 13:45
  • 1
    Try inserting g_varSkipRefreshOnFocus = true; before document.getElementById("openExcelCreate").click(); – user2536 Nov 15 '12 at 13:52
  • just saw it also on a website :) I'm trying it now – Ruben Herman Nov 15 '12 at 13:52
1

I have added g_varSkipRefreshOnFocus = true; before my onclick event is triggered and seems to work now:

<a id="openExcelCreate" href="<%= DocumentUrl %>" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','1','SharePoint.OpenDocuments','','','','1','0','0','0x7fffffffffffffff','','')">Download File</a>
<script type="text/javascript">
  g_varSkipRefreshOnFocus = true;
  document.getElementById("openExcelCreate").click();
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.