• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2026
  • Last Modified:

SharePoint 2010 Upload link

Hi,

We have a requirement where we would like to add an upload link in the menu. The code that I have is:

<a class="ms-addnew"
id="idHomePageNewDocument"
href="http://Site/Documents/_layouts/Upload.aspx?List={A6176004-C4B8-4684-9396-8DB0B207D75F}&amp;RootFolder="
onclick="javascript:NewItem2(event, &quot;http://Site/Documents/_layouts/Upload.aspx?List={A6176004-C4B8-4684-9396-8DB0B207D75F}&amp;RootFolder=&quot;);javascript:return false;"
target="_self">Upload new doc</a>

This works, but I need to call this script on a “onload” event.

The other code that I have is:

<script language="javascript" type="text/javascript">
    var addObj= document.getElementById("idHomePageNewDocument");
    if (addObj!=null) {
      addObj.href="http://site/Documents/_layouts/Upload.aspx?List={A6176004-C4B8-4684-9396-8DB0B207D75F}&amp;RootFolder=";
      addObj.onclick=null;
      }
 </script>
This code doesn’t do anything.

So what I really need to do is create a link in a menu to a page that has an onload event which opens the modal window for the upload.aspx

This cannot be that hard but I am not very good with Javascript.
0
Die_Antwoord
Asked:
Die_Antwoord
  • 6
  • 2
1 Solution
 
Mrugesh1Commented:
Try this

<html>
<head>
<script language="javascript" type="text/javascript">
function OpenLink()
{      
      var addObj= document.getElementById("idHomePageNewDocument");
      addObj.href="http://site/Documents/_layouts/Upload.aspx?List={A6176004-C4B8-4684-9396-8DB0B207D75F}&amp;RootFolder=";            
}
   
 </script>
</head>
<body onload="OpenLink()">
<a class="ms-addnew"
id="idHomePageNewDocument"
href="#"
onclick="javascript:NewItem2(event, &quot;http://Site/Documents/_layouts/Upload.aspx?List={A6176004-C4B8-4684-9396-8DB0B207D75F}&amp;RootFolder=&quot;);javascript:return false;"
target="_self">Upload new doc</a>
</body>
</html>
0
 
Die_AntwoordAuthor Commented:
Hi Mrugesh1,

Thank you for your quick response.

The thing is, don't want to click a link on the page, this should be an "onload" event.

Steps should be:
1. User selects upload link from menu.
2. Opens page with Javascript and "onload" loads Javascript that in return opens the modal window that contains the upload.aspx
0
 
Mrugesh1Commented:
As per my understing with ur question, below is the solution.

In upload.aspx page follow below steps,

1) In .aspx page, <body id="htmlBody" runat="server"> and under <head> part write below script
    <script language="javascript" type="text/javascript">
function OpenWindow()
{      
      var myArguments = new Object();
      window.showModalDialog("YourPageUrl", myArguments, '');
}
</script>
   
2) In .aspx.cs page under Page_Load event, write...
        htmlBody.Attributes.Add("onload", "OpenWindow()");
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Die_AntwoordAuthor Commented:
Hi Mrugesh1,

This is a SharePoint 2010 site and modifying the upload.aspx would make SharePoint unsuported.

Would I not be able to modify the following code to fire onload instead of onclick:

<script language="javascript" type="text/javascript">
function OpenLink()
{      
      var addObj= document.getElementById("idHomePageNewDocument");
      addObj.href="http://site/Documents/_layouts/Upload.aspx?List={A6176004-C4B8-4684-9396-8DB0B207D75F}&amp;RootFolder=";            
}

window.onload="OpenLink()">
<a class="ms-addnew"
id="idHomePageNewDocument"
href="#"
onclick="javascript:NewItem2(event, &quot;http://site/Documents/_layouts/Upload.aspx?List={A6176004-C4B8-4684-9396-8DB0B207D75F}&amp;RootFolder=&quot;);javascript:return false;"
target="_self">Upload new doc</a>
0
 
Die_AntwoordAuthor Commented:
Is there any JavaScript Gurus out there?
0
 
techExtremeCommented:
I guess your basic necessity is to open a custom page which should again popopen a upload modal popup.
Its possible. try this:

You can redirect user with appripriate parameters to your custom page.
Now have a <img> control on that page, you can set its' display to none to hide it.
Now you can use the onload function for that image and write the script that you have in there.

What will happen is that as soon as user gets redirected to that page and our image loads, it will call the onload function and your code will execute.

Happy Coding!
0
 
Die_AntwoordAuthor Commented:
Hi,
I need to add a link in SharePoint navigation that will enable the user to upload a document to a document library. This should open the SharePoint modal window.
This is a SharePoint 2010 solution. The user should end up on the page where he/she initiated the upload from.
The code that I have has is:
<a class="ms-addnew" id="idHomePageNewDocument"
href="http://site/Documents/_layouts/Upload.aspx?List={ListID}&amp;RootFolder=&"
onclick="javascript:NewItem2(event, &quot;http://site/Documents/_layouts/Upload.aspx?List={ ListID }&amp;RootFolder=&quot;);
javascript:return false;" target="_self">Upload new asset</a>
This code works but I am not able to get into the <a></a> tag of the navigation within SharePoint.
0
 
Die_AntwoordAuthor Commented:
I have a parcial solution on another post in Experts Exchange.

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27021841.html
0
 
Die_AntwoordAuthor Commented:
Closing due to another question posted.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now