SharePoint custom form - sharepoint

I am looking to create a page with a single form on it that does the following:
Contact a webservice with input from the form.
Perform an action (programmed using C#) depending on the result of the webservice call.
Since I am not interacting with any lists or similar on the SharePoint site, I was thinking a WebPart would be the simplest way to add the form and catch the submit-event, but I am not sure if this is the best practice or an easier/better way exists.
I also need to restrict access to the form to a specific usergroup.
Thanks in advance!

A new SharePoint Web Part is probably the most common way to provide this solution in SharePoint and fits your requirements well. Though your solution doesn't call for it, you do have access to the lists from custom web part code.
If you are using SharePoint 2007, Visual Studio Extensions provide the Microsoft supported way to create one easily. It's much easier with Visual Studio 2010 and SharePoint 2010.
Some other options would be an InfoPath Form with custom code or a custom application page with code behind. The benefit of the web part is that it works with all versions of SharePoint and can be added to any web part page on the site and customized by users. Also, the application page may not pick up the master page if you are on SharePoint 2007.

Use WebDAV to upload an ASPX page to a site in SharePoint. Then upload your assembly to each SharePoint server, the bin folder of your application is preferred, or add it to the GAC.
Your ASPX page might look like this:
<%# Page Language="C#" masterpagefile="~masterurl/custom.master" inherits="MyAssembly, MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c48b11b32c9eb4a7" %>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderPageTitle">My Title</asp:Content>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderPageTitleInTitleArea">My Page</asp:Content>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderMain">
<asp:Button runat="server" ID="ButtonClickMe" Text="Click Me!" />
</asp:Content>
Then your assembly might look something like this:
public class MyClass : Microsoft.SharePoint.WebPartPages.WebPartPage
{
protected global::System.Web.UI.WebControls.Button ButtonClickMe;
protected override void OnLoad(EventArgs e)
{
base.OnLoad( e );
ButtonClickMe.Click += new EventHandler( ButtonClickMe_Click );
}
void ButtonClickMe_Click(object sender, EventArgs e)
{
if (!Page.IsValid)
return;
// Do stuff here
}
}
You won't be able to edit the permissions of the ASPX page directly, but you can manipulate the permissions of the site it is in (thus, restrict the site to only the usergroup which you want to access the form).

Related

Remove canonical link from Sharepoint site

We have a main public site, abcd.com, which is using SharePoint Office 365 and another replica SharePoint site using this format - abcd-public.sharepoint.com.
For some reason,
<link rel="canonical" href="http://abcd-public.sharepoint.com:80/Pages/Home.aspx" />
shows up on every page our main public website (abcd.com). The path above changes depending on the page the user is on.
If I understand this correctly, this could be one of the reason why our site does not show up on google search result at all. If possible, we would like to reverse the behavior so the SharePoint version of the site has the canonical url = abcd.com.
or
Is there a way to completely remove the canonical url from the main website (abcd.com)? Or is there some sort of a setting that could help our site to show on google search result?
I had the same problem and the only solution that I found is create a webpart to put in the masterpage and in the prerender event of the webpart put this lines of code:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
HttpContext.Current.Items["CanonicalURLWithParameters"] = "http://example.com/customurl";
}
Sergio

SharePoint Link with QueryString Parameters

The task is to migrate classic ASP functionality to SharePoint Server 2013.
On the ASP page, a certain link is visible only if the authenticated user's password can be retrieved from a database. The link looks similar to:
<a target="_blank" href="https://www.someurl.com/secure/login.php?username=<%=strUserName%>&password=<%=rsOpenOrders("CL_password")%>" onmouseover="self.status=' '; return true;">
<img border="0" src="somelogo.gif" width="267" height="80" /></a>
I'm new to SharePoint, and I would appreciate your help (conceptual and code snippet) in solving this problem.
I understand that writing "code behind" is not highly encouraged with SharePoint pages and web parts.
So, what's the best alternative to be able to use the authenticated username value in building the first querystring parameter, and to query a SQLServer database to retrieve the value for the second querystring parameter? Please ignore the security concern here. Thanks!
its called SPSecurityTrimmedControl
example:
<%# Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" runat="server"
AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="ManageWeb" PermissionContext="CurrentSite">
<INCLUDE OUR CONTROL / CONTENT HERE>
</SharePoint:SPSecurityTrimmedControl>
I ended up creating custom web parts developed using Visual Studio 2013 for each particular link that needed query string parameters to be built based on values retrieved from database.

How to add custom user control in SharePoint 2013 HTML master page

I am trying to add custom usercontrol in SharePoint 2013 HTML master page, but its not working and showing the message
SharePoint can't parse this file, most likely because of an incorrectly formatted SharePoint snippet. The markup at the following location is causing problems. Edit the markup manually to fix it, or replace it with a new snippet from the Snippet Gallery.
Invalid SharePoint markup at line 145. Please repair or recreate the markup
following is the code snippet for HTML master page.
<!--CS: Start Create Snippets From Custom ASP.NET Markup Snippet-->
<!--SPM:<%# Register Src="~/_controltemplates/15/SharePointProject1/UserControl1.ascx" TagPrefix="uc1" TagName="MyDepartmentControl" %>-->
<!--SPM:<uc1:MyDepartmentControl runat="server" id="MyDepartmentControl1" />-->
<!--CE: End Create Snippets From Custom ASP.NET Markup Snippet-->
Please help me how i can make it possible to add asp.net user-control in SharePoint 2013 HTML Master page.
Thanks in advance.
I just solved this problem.
The answer is; convert this line
<!--SPM:<%# Register Src="~/_controltemplates/15/SharePointProject1/UserControl1.ascx" TagPrefix="uc1" TagName="MyDepartmentControl" %>-->
to
<!--SPM:<%# Register TagPrefix="uc1" TagName="MyDepartmentControl" Src="~/_controltemplates/15/SharePointProject1/UserControl1.ascx" %>-->
Have fun..

Apply Web Part Connections to web parts on the ascx page of other web parts

I have created a visual web part that combines two other previously created web parts into one nicely styled web part. This is done simply by adding Register tags to the ascx page of the web part, and then adding the web part tags just as I would on a page layout, like so:
WebPart_ParentAssignmentsUserControl.ascx:
<%# Register tagprefix="WebParts" namespace="Microsoft.SharePointLearningKit.WebParts" assembly="Microsoft.SharePointLearningKit, Version=1.3.1.0, Culture=neutral, PublicKeyToken=24e5ae139825747e" %>
<%# Register tagprefix="MyChildrenWebPart" namespace="MLG2010.WebParts.MyChildren.MyChildrenWebPart" assembly="MLG2010.WebParts.MyChildren, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" %>
<WebParts:AssignmentListWebPart runat="server" ListScope="false" AllowEdit="True" AllowConnect="True" Title="Assignment List Web Part" IsIncluded="True" Dir="Default" SummaryWidth="150px" IsVisible="True" AllowMinimize="True" AllowHide="True" ExportControlledProperties="True" ZoneID="" ID="g_1c528b46_baf2_4cf2_a004_91f84c4f4556" FrameState="Normal" DisplaySummary="True" ExportMode="All" SuppressWebPartChrome="False" DetailLink="" HelpLink="" MissingAssembly="Cannot import this Web Part." PartImageSmall="" AllowRemove="True" ToolTip="Assignment List - Use this web part to keep track of your SharePoint Learning Kit assignments." HelpMode="Modeless" FrameType="Default" AllowZoneChange="True" PartOrder="0" Description="Display the assignments for an instructor or learner." PartImageLarge="" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{1c528b46-baf2-4cf2-a004-91f84c4f4556}" WebPart="true" Height="" Width=""></WebParts:AssignmentListWebPart>
<MyChildrenWebPart:MyChildrenWebPart runat="server" PageSize="5" StudentsSiteURL="/student" PictureLibraryTitle="Students Picture Library" ADChildAttribute="otheripphone" Description="My WebPart" DefaultPictureURL="../../Students Picture Library/DefaultChild.jpg" ShowErrors="True" PictureLibraryUrl="../../Students Picture Library" Title="MyChildrenWebPart" ADEntryPoint="LDAP://dc=redconnect-test" __MarkupType="vsattributemarkup" __WebPartId="{d13a3729-e2b8-4436-ac1b-b75c914a3596}" WebPart="true" __designer:IsClosed="false" id="g_d13a3729_e2b8_4436_ac1b_b75c914a3596"></MyChildrenWebPart:MyChildrenWebPart>
The problem here, is that I need these two web parts to communicate via web part connections. since they are only added here on the aspx, sharepoint does not "know" about them, and thus they do not get a chrome and thus I cannot set up the web part connections in the browser.
Is there a way to set up web part connections on web parts that are added this way? Or maybe if I can just activate the chrome on these web parts?
You can define the connection statically. Note that using this way, you cannot create/modify/delete the connection using the browser.
See:
How to: Declare a Static Connection between Two Web Parts Controls
In the end, I separated the web part into the pieces that could connect normally, and then used styling to make it look as if they were one. I have not found any documentation on the consequences of putting web parts inside other web parts as i attempted.

I've got a sharepoint solution, what next

I'm new to sharepoint. I have a C# solution, that has masterpages and user-controls to be used in a sharepoint site. I have setup my sharepoint dev VM and i can browse the default sharepoint stuff.
How do I add the master pages to Sharepoint? Where do I go from here?
My suggestion would be to deploy the master pages as a feature rather than a manual process. Solutions (WSPs) and Features are the supported way to deploy content/features into sharepoint. A really great tool for sharepoint development is called WSPBuilder
A master page is deployed into sharepoint as a "module" that you will place into your elements.xml file in the feature.
Think of a solution as a .cab file with a different extension. Within that is a file called feature.xml which defines the title of your package when its deployed. Features can be activated and deactivated to deploy and undeploy your content into parts of your farm.
Here is an example of a css file deployed as a Module... Master pages would be similar however, they would deploy into the master page gallery rather than the style library. This module deploys a custom css file into the "Style Library" of a site collection. After this is deployed I used a "Feature Receiver" (event handler) to grab a reference to the SPSite object and modify its alternate stylesheet so that my override took place.
Feature.xml
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="63BB13A0-1F9C-4c3b-BE60-10E59CEE0113"
Title="Custom CSS Feature"
Description="Deploying a custom CSS using a feature"
Version="1.0.0.0"
Hidden="FALSE"
Scope="Site"
ReceiverAssembly="CustomCSSFeature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=24f1377a8414d2ed"
ReceiverClass="CustomCSSFeature.FeatureReceivers.CustomCSSFeatureReceiver"
>
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
elements.xml - you'd modify this to reflect where master pages are supposed to be deployed I would think that this is the Url property. The Path="Styles" refers to the relative path within the feature itself where the style sheet resides (e.g. in your visual studio i have a sub folder called styles beneath the folder called CustomCSSFeature and that is where the style sheet exists)
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="OSGStyles" Url="Style Library" Path="Styles" RootWebOnly="TRUE">
<File Url="custom-css.css" Type="GhostableInLibrary" />
</Module>
</Elements>
Then, in my feature receiver class I have activated/deactivated handlers which "apply" the stylesheet to the publishing web. In your case you can likely change the default master page for the website in a feature receiver as well.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.OpenWeb())
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.AlternateCssUrl.SetValue(web.ServerRelativeUrl +
"/Style Library/custom-css.css", true);
publishingWeb.Update();
web.Update();
}
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.OpenWeb())
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.AlternateCssUrl.SetValue("", true);
publishingWeb.Update();
web.Update();
}
}
Copy them to SharePoint root (For SP 2007 default location is C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\, for SP 2010 instead of "12" you have "SharePointRoot")
From there, copy your files to \TEMPLATE\LAYOUTS folder and then you can reference masterpage from your aspx pages like "/_layouts/mymasterpage.master".
UserControls goes into \TEMPLATE\CONTROLTEMPLATES
Get to know the directory structure in the 12 Hive
Exploring the 12 Hive : TEMPLATE Directory
Another way is to put your masterpage in master pages list. Use this link to access master page list and upload your masterpage: http:///_catalogs/masterpage
You can add master pages using the SharePoint Designer 2007.
Generally i recommend you to take a look at the answers of this question: Learning Sharepoint

Resources