How to call an external Javascript file from a webpart - sharepoint-2010

I'm building a Web Part for SharePoint 2010 and I would like to add a simple modal.
I've registered the external js script as follows:
ScriptLink.Register(this.Page, "js/jquery-1.5.min.js", true);
ScriptLink.Register(this.Page, "js/jquery.simplemodal-1.4.1.js", true);
Somehow I'm getting that a message saying that the file was not found, because it's looking at 1033/_layouts directory, or something like that.
So, my question is: how could I reference an external JavaScript file from my webpart, without placing them at that directory?

In my opinion, you should be deploying your scripts to layouts, along with images, stylesheets, etc. that are not intended to be customized by your users.
You can map the folder "Layouts" to your project in VS 2010.
Then add subfolders to reflect your project name, etc. (Right click on project -> Add-> SharePoint "layouts" Mapped Folder)
Layouts
- ProjectName
- - Scripts
- - - jquery-1.5.min.js
Then, when you deploy your solution, the scripts will be copied to the proper location..
In your webpart, you can reference your scripts like:
In code:
ScriptLink.Register(this.Page, "ProjectName/Scripts/jquery-1.5.min.js", false);
But, I prefer in the .ascx:
<SharePoint:ScriptLink ID="ScriptLink2" Name="ProjectName/Scripts/jquery-1.5.min.js" runat="server" OnDemand="false" Localizable="false" />

If you set "Localizable" attribute to "false" on the ScriptLink tag then it will omit the "1033" folder.

I'm not sure if this still works in SharePoint 2010, but here is how I did it in SharePoint 2007:
ScriptLink.Register(this.Page, "js/jquery-1.5.min.js", true);
List<string> list = (List<string>)HttpContext.Current.Items["sp-ScriptLinkValues"];
int index = list.Count - 1;
string item = list[index];
list[index] = item.Replace("/_layouts/1033/js",
"http://ajax.googleapis.com/ajax/libs/jquery/1.5");

If you add another "content editor" web part, you can place your "Include" code of the JavaScript file there with the complete file location.

Related

Sharepoint2010 custom list view, changing setuppath post production to new AllItems.aspx

I have a custom list definition in production environment with list instances created with the following definition:
<View BaseViewID="0" Type="HTML" WebPartZoneID="Main" DisplayName="All Items" DefaultView="TRUE" MobileView="True" MobileDefaultView="False" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/issues.png" Url="Forms/AllItems.aspx">
I need to changing the setup path in some way so the AllItems.aspx view of the document library displays documents from it's parent site document library by e.g. CQWP. I've attempted this by using SPView.SetViewXml() but this has no affect.
I have attempted to follow Stefan Stanev's SharePoint blog
I've successfully changed the setup path in development with Unghost a custom SPView but I really do not want to go down this path.
I have customized the viewpage.aspx by mapping to templates\pages and editting / adding the required web part and adding feature upgrading to create a new view set it as default, change the ViewXml by calling SPView.SetViewXml but this does not work.
Is there a way of updating the content database post production to change and customise AllItems.aspx of a custom document library without directly querying content database?

Mapping a widget template to a user control in SiteFinity 5

(Crossposted in SiteFinity's forums)
I'm using SiteFinity 5.0. I created a custom module, using the module builder, called Promos. It's content type is called Promo.
Next, I created a new widget template called PromoFlexSpace. I basically copied the auto-generated template for a single Promo display and changed it a bit.
What I would like to do is globally map this widget template to a user control, so that any time that template is selected, it actually uses my user control. I've found how to do this for an individual item:
http://www.sitefinity.com/documentation/documentationarticles/designer-s-guide/widget-templates/using-external-widget-template-file
http://www.sitefinity.com/blogs/joshmorales/posts/11-05-10/mapping_external_templates_for_sitefinity_4_widgets.aspx
And I found something that came close to explaining what I'm trying to do on a global level:
http://www.sitefinity.com/blogs/joshmorales/posts/11-07-26/customizing_sitefinity_4_controls_with_the_viewmap.aspx
But I haven't found a way to accomplish what I'm trying to do yet (apologies if that last link actually does explain it - I need a better breakdown if it does).
What I've tried so far is going into the advanced settings > controls > view map and adding an entry there, but I can't find a value for HostType that works.
If you go to Administration > Settings > Advanced > Toolboxes > ... > [Your Widget Control] there's a setting for "LayoutTemplate" where you can enter a path to an .ascx file.

SharePoint 2010,SandBox Solution,uploaded .STP files to _catalogs/lt using Feature not coming in GetCustomListTemplates

I have sandbox solution which has 2 features (both are sitecollection level features)
I am activating both feature using same USER.
feature 1 : that uploads .stp files to _catalogs/lt folder via module file
feature 2 (is dependent on feature 1) : it will get all .stp file via .GetCustomListTemplates(spweb) method from _catalogs/lt, but there are no files coming in
here is my code
using (SPSite mySite = properties.Feature.Parent as SPSite)
{
using (SPWeb spWeb = mySite.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPListTemplateCollection listTemplates = mySite.GetCustomListTemplates(spWeb);
}
}
listTemplates has no .stp files.it is coming out empty.
pls help me ...
Does your list template derive from one of the default list templates like "Discussion Board"? I noticed that when I tried to do the following I encountered the same problem as you:
Save a SharePoint 2007 "Discussion Board" list as a list template
Use the method in this blog to convert the template to SharePoint 2010
Upload the template to my SharePoint 2010 site
I noticed that the default "Discussion Board" list template was not even an option for creating a new list in SharePoint 2010. Therefore I went to the site features and and turned on the "Team Collaboration Lists" just to enable the default "Discussion Board" list template.
After doing that both the default "Discussion Board" list template and my custom "Bulletin Board" template showed up when I went to create a new list. Then I went to my powershell script and noticed that GetCustomListTemplates returned my custom template. I'm assuming that means the C# should work as well.
Here is the list from the old SharePoint 2007 website:
Here is the collaboration feature that enables the "Discussion Board" list template in the new SharePoint 2010 website:
Here is the menu for creating a new list in the new SharePoint 2010 website AFTER enabling the team collaboration lists feature:
As you can see the "BulletinBoard" image is the same as the "Discussion Board" image so SharePoint probably couldn't use the "BulletinBoard" template because the "Discussion Board" template was not yet installed.
If you use the Record Center as the template for your root website in SharePoint 2010, GetCustomListTemplates() will always return 0 (zero).
There is some weird bug that makes this happen.
Here is code that you can try running in the SharePoint PowerShell. The return value for GetCustomListTemplates($web).Count will be zero if you have the root web made from the Record Center template.
$site = get-spsite("http://localhost")
$web = $site.RootWeb
$list = $web.Lists["TestDocLibrary"]
$list.SaveAsTemplate("MyListTemplate.stp", "MyListTemplate", "My List Template", $false)
$site.GetCustomListTemplates($web).Count
More information can be found at the following web pages:
http://social.msdn.microsoft.com/Forums/ar/sharepoint2010general/thread/c5455a27-360a-465c-91d5-f81beeac6789
http://sharepointrecordsmanagement.com/2011/02/
Good luck!
- Jason

How can find out what features have activated when I create a site collection using a out of box site definition

I plan to create custom site using web template.I need to find out what features have activated when I create a site collection using a out of box site definition.How can I do it?
You can find it out from the Site Definition file located at 14\Template\SiteTemplates. For each configuration of the site template there are "SiteFeatures" and "WebFeatures" elements which lists what features needs to be activated when a new site is created using that site template (and configuration). Remember that if those features depend on any other features which are hidden, they will also be automatically activated.
I believe you know how to locate the ONET.xml file for the out of the box site definition. If not, following PowerShell command will help you.
Get-SPWebTemplate | where { ( $.'IsHidden' -eq [System.Boolean]$False ) -and ( $.'IsSubWebOnly' -eq [System.Boolean]$False ) }
The Name property in above result includes the name of the folder in which to look for Onet.xml and the configuration setting inside the onet.xml file.

SharePoint 2010: custom masterpage for programmatically created subsites

What’s the best way to add a custom masterpage to a subsite that is being created programmatically in a feature event receiver? Each of these 50 subsites gets its own “_catalogs/masterpage”, so I have a feeling that Elements.xml for the root-site’s Module/Elements.xml is out. More feature receiver code? PowerShell post-deployment processing?
Is this going to be 50 copies of the same Master Page?
If not, I can't really picture how the Master Page will be specially made using code, but also a Feature Module element is certainly out.
But if it is 50 copies of the same file, you could deploy the Master Page to the Gallery one time using a Feature Module element. Then in your Feature Receiver, make a copy of that file with a new name in the Master Page Gallery and attach it to your website:
web.MasterUrl = "_catalogs/masterpage/custom_v4.master";
web.CustomMasterUrl = "_catalogs/masterpage/custom_v4.master";
web.Update();
You might want to think about creating
custom site definition.
You have following choices to set master page for the site:
1) Using Sharepoint Browser UI (from Site Settings page)
2) Using Custom site definitions
3) Programmatically
4) Using SharePoint Designer
Looking at your scenario, no 3 is an option. You may want to do it in the Feature Receiver itself.