I got a code to create custom SharePoint list using Visual Studio 2010. But where can I place this code in Visual Studio 2010 was not mentioned anywhere. Can somebody help me please? I am really struggling. Here is the code:
using (SPSite oSPsite = new SPSite("http://Web URL"))
{
oSPsite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
oSPWeb.AllowUnsafeUpdates = true;
/* 1. create list from custom ListTemplate present within ListTemplateGalery */
SPListTemplateCollection lstTemp = oSPsite.GetCustomListTemplates(oSPWeb);
SPListTemplate template = lstTemp["custom template name"];
oSPWeb.Lists.Add("List Name", "Description", template);
/* 2. create list from sharepoint list content type (e.g. Links) */
oSPWeb.Lists.Add("List Name", "Description", SPListTemplateType.Links);
oSPWeb.AllowUnsafeUpdates = false;
}
oSPsite.AllowUnsafeUpdates = false;
}
You could put this in a client application (Console, WinForms, WPF). The only restriction would be that the app will only work if it is executed on the SharePoint server. It will not work remotely.
Another way would be to create a SharePoint Feature and include the code in the Feature Receiver. Chapter 3 of Inside Microsoft SharePoint 2010 describes the process of building a Feature and attaching a Feature Receiver.
http://msdn.microsoft.com/en-us/library/ff872401.aspx
This code can be executed from all the places where you can execute code in sharepoint depending on the requirement , here are some
A webpart i.e. the code behind for the webpart
It can be a part of a sharepoint page that run with code behind (http://blogs.msdn.com/b/kaevans/archive/2010/06/28/creating-a-sharepoint-site-page-with-code-behind-using-visual-studio-2010.aspx)
A SharePoint Timer Job http://blogs.msdn.com/b/guruketepalli/archive/2013/02/12/10259696.aspx
It can be a part of a list event handler/receiver or a web event receiver ( http://msdn.microsoft.com/en-us/library/ff407274(v=office.14).aspx )
Run from some client side application
Related
I am in the progress of rewriting some code to work with ASP 5.
The old code does the following:
string Local_IP=Request.ServerVariables["LOCAL_ADDR"];
string HTTP_reverse_VIA = Request.ServerVariables["HTTP_REVERSE_VIA"];
How do I get the corresponding information from ASP 5?
HttpContext has the GetFeature method, using this method we can get feature information.
Here we are want to get Server Variables of IIS; check project.json "Microsoft.AspNet.Server.IIS" is used for running ASP.NET 5.
We have to use GetFeature of 'Microsoft.AspNet.Server.IIS' which contains Server variables feature. use the below code
var varibleFeature = Context.GetFeature<Microsoft.AspNet.Server.IIS.Features.IServerVariablesFeature>();
if (varibleFeature != null)
{
var valuesList = varibleFeature.ServerVariables;
//read through valuesList dictionary for Server Variables
}
Since I was running on IIS Express, it gave few variables but not the one mentioned in your question.
Please deploy it on IIS and explore more.
When i tried to create another type of an entity record in the post update plugin stage I have gotten "Changing security attributes is not allowed in stage 20 plugins" error.
Its working fine in Dynamics CRM 2013 SP1 CRM.
After update CRM 2013 to CRM 2015 i got this error
Remove logic from pre create and move it to post create of the other entity. then it will working fine
Remove unwanted attribute from plugin images.only select attribute that you need in the plugin.You can set it when you registering plugin(don't tick all attributes check box).remove security related attribute(owner, modified by, created on)
Some of you might get this error in the plugin steps when an organization is being migrated to CRM 2015.
Cause:
You change the ownership of the record in the record Pre-creation
Resolution:
Most solutions out there say about change the plugin to Post-operation stage, but this don't make sense for some of the actions/checks that your plugin could do.
So, what you could do is to check the pipeline stage before you run the assignment operation.
https://msdn.microsoft.com/en-us/library/gg327941.aspx#bkmk_PipelineStages
Sample code:
//Runs on the Pre-Validation step, when a Contact is created
if (context.Stage == 10)
{
if (!targetEntity.Attributes.Contains("parentcustomerid"))
{
throw new InvalidPluginExecutionException("Message to show....");
}
try
{
var accountOwner = (from a in orgServiceContext.AccountSet
where a.Id == targetContact.ParentCustomerId.Id
select a).Single();
targetEntity.Attributes["ownerid"] = new EntityReference("team", accountOwner.OwnerId.Id);
targetEntity.Attributes["owningbusinessunit"] = new EntityReference("businessunit", accountOwner.OwningBusinessUnit.Id);
}
catch
{
throw new InvalidPluginExecutionException("Message to show...");
}
}
Found another solution: Move your plugin step to Pre-Validation.
I'm coding a c++/c# client-application to communicate with a Sharepoint 2010 site which uses Taxonomy
I have downloaded and installed Microsoft.Sharepoint.Client.Taxonomy.dll from:
http://download.microsoft.com/download/E/1/9/E1987F6C-4D0A-4918-AEFE-12105B59FF6A/sharepointclientcomponents_x64.msi
The client user may enter values in a form by selecting values from a dropdown of values collected from a Taxonomy TermSet. In order to fetch the TermSet I must first get a TaxonomySession:
TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
clientContext.Load(taxonomySession,
ts => ts.TermStores.Include(
store => store.Name,
store => store.Groups.Include(
group => group.Name))
);
try
{
clientContext.ExecuteQuery();
}
catch (Exception e)
{
string err = e.Message; // Cannot find proxy for type with id "{981cbc68-9edc-4f8d-872f-71146fcbb84f}"
}
I'm uncertain whether the reason is that it is illegal to use Microsoft.Sharepoint.Client.Taxonomy.dll (Sharepoint 2013) against a Sharepoint 2010 server or whether I'm doing something wrong
The use of the Microsoft.Sharepoint.Client.Taxonomy.dll (Sharepoint 2013) against a Sharepoint 2010 server will only render errors.
There is one service side dll for sharepoint 2010 (Microsoft.Sharepoint.Taxonomy.dll), but then you have to be on one sharepoint machine in the farm. (Requires .NET 3.5 I think, won't work in .NET 4.0)
I'm Stuck the following problem: How can I link a PDF Document to a Record in a Data Grid using Visual Studio LightSwitch 2011 and Visual Basic?
Any help would be awesome, thanks!
Here's the simplest way to do this: add a custom command to the Command Bar of the Data Grid Row for your Data Grid. In this example I'm calling the command Open PDF File. Then add this code to Execute code for the command:
partial void OpenPDFFile_Execute()
{
const string LOCAL_SERVER_PDF_DIR = #"\\MyServer\PDFs\";
const string WEB_SERVER_PDF_DIR = "http://myweb.server/PDFs/";
const string PDF_SUFFIX = ".pdf"; //assumes you do not include the extension in the db field value
if (AutomationFactory.IsAvailable)
{
//if the AutomationFactory is available, this is a desktop deployment
//use the shell to open a PDF file from the local network
dynamic shell = AutomationFactory.CreateObject("Shell.Application");
string filePath = LOCAL_SERVER_PDF_DIR + this.PDFFiles.SelectedItem.FileName + PDF_SUFFIX;
shell.ShellExecute(filePath);
}
else
{
//otherwise this must be a web deployment
//in order to make this work you must add a reference to System.Windows.Browser
//to the Client project of your LS solution
var uri = new Uri(WEB_SERVER_PDF_DIR + this.PDFFiles.SelectedItem.FileName + PDF_SUFFIX);
HtmlPage.Window.Navigate(uri, "_blank");
}
}
You will need to add the following imports to the top of your user code file to make this code compile:
using System.Runtime.InteropServices.Automation;
using System.Windows.Browser;
I should mention that you need a directory to server the PDFs up from. This example is flexible with respect to deployment, because it handles both desktop and web configurations. Since you'll need to set up the PDF directoy, you may want to just handle one configuration option to simply things (or you could expose the same PDF directory over http and as a local network share).
You may also want to present this as a true link instead of a button. In order to do this, you'll need a custom SilverLight control. In any case, I would recommend implementing the PDF link using a button first. You can then move this same code to a link event handler as a separate project if that is worth spending time on.
I want to "simulate" the Right click/Update service reference command in a VS2010 addin. I have a reference to the containing (Silverlight...) project, I know the name of the service reference and the url of the service.
I've found this: http://dedjo.blogspot.com/2007/03/adding-web-references-to-your-vs.html , but it only works for asmx (it uses System.Web.Services instead of System.ServiceModel), not wcf.
Is there any choice but call svcutil from code? if so, how? (do I use svcutil or slsvcutil? How do I call it from inside the addin?)
thanks
I believe the visual studio command for this is "Project.UpdateServiceReference". So I guess you can try to select the node you're interested in, and run this command, like this:
envDTE.Windows.Item(vsWindowKindSolutionExplorer).Activate();
envDTE.ActiveWindow.Object.GetItem(#"MyProject\Service References\Proxy").Select(vsUISelectionType.vsUISelectionTypeSelect);
envDTE.ExecuteCommand("Project.UpdateServiceReference");
If you're looking for the more programmatic way to do this, you can do something like the following. This approach does not require using the DTE automation layer which will change the user's selection and execute a command. Note that this is within the context of a VSPackage with an IServiceProvider so that it can get instances to the core Visual Studio interfaces, etc...
You may also be able to do this from within an Addin, but you'd need to get an IServiceProvider and add references to (at least) Microsoft.VisualStudio.Shell.Interop.dll and Microsoft.VisualStudio.WCFReference.Interop. Reference assemblies for these binaries are available in the Visual Studio 2010 SDK.
IVsSolution solution = GetService(typeof(SVsSolution)) as IVsSolution;
if (solution != null)
{
IVsHierarchy solutionHierarchy = solution as IVsHierarchy;
if (null != solutionHierarchy)
{
IEnumHierarchies enumHierarchies;
Guid nullGuid = Guid.Empty;
ErrorHandler.ThrowOnFailure(solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_ALLINSOLUTION, ref nullGuid, out enumHierarchies));
if (enumHierarchies != null)
{
uint fetched;
IVsHierarchy[] hierarchies = new IVsHierarchy[1];
IVsWCFReferenceManagerFactory wcfReferenceManagerFactory = GetService(typeof(SVsWCFReferenceManagerFactory)) as IVsWCFReferenceManagerFactory;
if (wcfReferenceManagerFactory != null)
{
while (enumHierarchies.Next(1, hierarchies, out fetched) == 0 && fetched == 1)
{
if (wcfReferenceManagerFactory.IsReferenceManagerSupported(hierarchies[0]) == 1)
{
IVsWCFReferenceManager referenceManager = wcfReferenceManagerFactory.GetReferenceManager(hierarchies[0]);
var referenceGroupCollection = referenceManager.GetReferenceGroupCollection();
referenceGroupCollection.UpdateAll(null);
}
}
}
}
}
}
I'd also recommend looking at the WCF Service Consumption Tools samples for the Visual Studio 2010 SDK.