Link to home
Start Free TrialLog in
Avatar of Die_Antwoord
Die_AntwoordFlag for South Africa

asked on

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.
Avatar of Mrugesh1
Mrugesh1

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>
Avatar of Die_Antwoord

ASKER

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
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()");
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>
Is there any JavaScript Gurus out there?
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!
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.
ASKER CERTIFIED SOLUTION
Avatar of Die_Antwoord
Die_Antwoord
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Closing due to another question posted.