How to add discussion board in page automatically in Sharepoint 2010? - c#

We create a discussion board in Sharepoint 2010 without much effort, but I am looking for a solution where discussion board and all its replies are added to the certain zone automatically. That is end user do not need to add discussion board, through the process of entering page into edit mode and then adding web part. But instead, once user create a discussion board, all discussions and message are added to the page automatically (to certain zone in page).
Thanks.

Add this code the a web event handler (ListAdded) in order to run this code automatically. In that code you will need to check if the list type is of Discussion. In the event receiver you will need get a reference to the SPWeb in which you want to add the web part, and to the list you want to use (in this example the Contacts list). Next you create an instance of the ListViewWebPart class, in which you can set the ZoneID, the ListName and the ViewGuid. This is the tricky part, the ListName property should contain the ID of your list (a GUID), not the name of your list!! But the ListName property is of the type string, so you need to convert the List GUID to a string using .ToString(“B”).ToUpper(). The same goes for the ViewGuid. Finally you need to get a reference to the WebPartCollection for the page in which you want to add the web part (in this example the home page, being default.aspx). Now you can add the web part using the Add method.
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
// Get a reference to a web and a list
SPSite site = new SPSite("http://localhost:8000");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Contacts"];
// Instantiate the web part
ListViewWebPart wp = new ListViewWebPart();
wp.ZoneID = "Left";
wp.ListName = list.ID.ToString("B").ToUpper();
wp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
// Get the web part collection
SPWebPartCollection coll =
web.GetWebPartCollection("default.aspx",
Storage.Shared);
// Add the web part
coll.Add(wp);

Related

TFS 2018 API: Can access workitems but not workitem API end point

I created a middleware app that will pull work item data from TFS.
I was able to do this using the workitems end point.
http://sampleserver:8080/tfs/sampleproject/_apis/wit/wiql?api-version=4.0/workitems?ids=1,2,3
Now, I also need to get the work item links per work item. Per docu I would need to access the workitem with expand items. But unfortunately, work item end point does not seem to work.
http://sampleserver:8080/tfs/sampleproject/_apis/wit/wiql?api-version=4.0/workitem/3
Am I missing something here?
According to your description, looks like you just want the URL of created WorkItem, so that anyone when click on URL, created Work Item will be Open.
https://tfsurl:8080/tfs/DefaultCollection/PatrickProject/_workitems/edit/172/
The URL should be above format and here DefaultCollection is the collection name and the PatrickProject is the project name. I used this url and got rid of the id '172' in this case and use the ID of newly created work item. This would return the URL to go to the work item HTML page.
So it's a fixed format, if you have Newly Created WorkItem ID and collection name , project name, you just need to follow above format and change the last value of work item ID. That's it , ignore of which work item type you created.
If you want do this with code, do not use Rest API, you need to use client API, sample snippet:
var tfsURI = new Uri("http://test:8080/tfs");
var networkCredential1 = new NetworkCredential("test", "test!");
ICredentials credential = (ICredentials)networkCredential1;
Microsoft.VisualStudio.Services.Common.WindowsCredential winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(credential);
VssCredentials vssCredentials = new VssCredentials(winCred);
using (TfsTeamProjectCollection collection = new TfsTeamProjectCollection(tfsURI, vssCredentials))
{
collection.EnsureAuthenticated();
TswaClientHyperlinkService hyperlinkService =
collection.GetService<TswaClientHyperlinkService>();
String TFSurl = hyperlinkService.GetWorkItemEditorUrl(17648).ToString(); //17648 WorkItem ID
}
Hope this Helps!
To get specific work item information you need to use the Get Workitem API call so try http://sampleserver:8080/tfs/sampleproject/_apis/wit/workitems/3?api-version=4.0 instead.
You can also use this http://sampleserver:8080/tfs/sampleproject/_apis/wit/workitems/3?$expand=Links&api-version=4.0 and this will return the work with Id of 3 and all it's links (parent, attached files, changetset, etc.)
Notice that the api-version=4.0 with change depending on the version of TFS/Service you are using and should always be the last string in the REST call.

Using Microsoft's EWS to create online Lync/Skype meeting

Anybody knows how to create meeting request with online conference(Lync/Skype) using EWS?
So my approach is first getting an online and regular meeting created via Outlook and then simulate the creation of event with the same property.
Here is my code snippet for getting the meeting (calendarView is already initialized with start date, end date etc.):
ExtendedPropertyDefinition extendedOnlineMeetingProperty =
new ExtendedPropertyDefinition(new Guid("{00062008-0000-0000-c000-000000000046}"), 34112,
MapiPropertyType.Integer);
var properties = new PropertySet(
ItemSchema.Id,
AppointmentSchema.ICalUid,
ItemSchema.Subject,
AppointmentSchema.Start,
AppointmentSchema.End,
AppointmentSchema.Organizer,
AppointmentSchema.Location,
AppointmentSchema.LegacyFreeBusyStatus,
AppointmentSchema.IsCancelled,
AppointmentSchema.ICalRecurrenceId,
AppointmentSchema.MyResponseType, // Mandatory Meeting.MyResponseType can be retrieved without a search in the participant list
ItemSchema.LastModifiedTime,
AppointmentSchema.IsOnlineMeeting,
AppointmentSchema.IsMeeting,
ItemSchema.DisplayTo) { };
properties.Add(extendedOnlineMeetingProperty);
var activeResults = service.FindAppointments(WellKnownFolderName.Calendar, calendarView).ToList();
if (activeResults.Count > 0)
{
service.LoadPropertiesForItems(activeResults, properties);
}
I got the property IsOnlineMeeting with the correct bool value (tested -
created online and regular meeting with Outlook) in variable activeResults but I do not understand where to get conference link and other Lync/Skype properties needed for joining a conference.
Also I am not sure where and how to assign the values of Lync/Skype conference URL and other properties.
Sometimes I ask myself if it's worth it to developed some app based on MS products since their documentation suck.
After one week of cursing MS I have found a solution. Using the tool MFCMAPI you can check what property and their values your item in mailbox have.
download the program link
build and run it
Session - Logon - choose your mail profile - pick the mailbox and double click
actions - open special folder - calendar - double click on calendar
open the item with online S4B/Lync conference
the UC* properties are the one I was looking for.
If you open the property you can see something like this on the top:
ag: 0x8096001E
Type: PT_STRING8
DASL: http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/UCMeetingSetting
Named Prop Name: UCMeetingSetting
Named Prop Guid: {00020329-0000-0000-C000-000000000046} = PS_PUBLIC_STRINGS
So my definition of the extended property was wrong. It is not only one property but actually you need all 7 of them.
So the definition should be:
private static ExtendedPropertyDefinition CreateOnlineMeetingProperty()
{
ExtendedPropertyDefinition extendedUCMeetingSetting =
new ExtendedPropertyDefinition(new Guid("{00020329-0000-0000-C000-000000000046}"), "UCMeetingSetting",
MapiPropertyType.String);
return extendedUCMeetingSetting;
}
With the correct extended definition you can get the values from the item easily.
accessing the Value of ExtendedProperties
Calling TryGetProperty
var activeResults = service.FindAppointments(new
FolderId(WellKnownFolderName.Calendar, resource.Email),calendarView).ToList();
service.LoadPropertiesForItems(activeResults, properties);
foreach (Appointment result in activeResults)
{
// 1.
var b = result.ExtendedProperties[1].Value;
// 2.
string UCMeetingSetting;
result.TryGetProperty(extendedUCMeetingSetting, out UCMeetingSetting);
}
using steps above you can get whatever extended property you want, not only Unified Communications (UC) properties.
Ok, I managed to have this working (almost!) by setting just one of the extended properties:
appointment.SetExtendedProperty(
new ExtendedPropertyDefinition(
new Guid("00020329-0000-0000-C000-000000000046"),
"OnlineMeetingExternalLink",
MapiPropertyType.String
),
skypeMeeting.JoinUrl
);
I say almost because the appointment doesn't look exactly like a Skype meeting when you open it in Outlook: doesn't have the footer will the Join link and phone number etc.
Maybe there are other differences, but for now we see it in Skype for business with the Join button and also we see the it in the Outlook reminder with the Join button.
As a workaround, we have to hard-code the body content of the appointment.
Also conference ID, can be taken using UCWA 2.0 (https://learn.microsoft.com/en-us/skype-sdk/ucwa/myonlinemeetings_ref)
We used UCWA 2.0 to create the Skype conference call and attached it to the EWS appointment object.

how to do API calls of Kentico using ASP.NET MVC?

I'm struggling with API calls of Kentico forms using ASP.NET MVC, so that I can use AngularJS to display the return data (JSON format).
Specifically, my client is using Kentico on their server to create data using "Forms" on Kentico and I want to get the records stored in these forms via API calls using ASP.NET MVC. What I'm thinking is that in the general section of the "Forms", I see the "Form code name" showing that "Code name is a string identifier of the object that can be used by developers in API calls or URLs". But it seems to be there's no good example of it on internet. Keep trying to search it but no luck. I also tried to access data directly in SQL Server in which kentico stores the data. But the table's name that Kentico uses in SQL Server to store the data is different from the ones in "Forms" or "Custom tables" in Kentico.
Hope someone can show me how to do it and I really appreciate it. Thanks in advance.
There is a very good example in the official documentation of Kentico.
Please note that Forms have been renamed a few times in the past (they were called BizForms and On-Line forms) that's the reason why the code below references CMS.OnlineForms and uses BizFormInfoProvider. It might also very well be the reason why you didn't find any good example :)
The example below shows how to retrieve Form's definition (metadata), get all the data and iterate through it.
using CMS.OnlineForms;
using CMS.DataEngine;
using CMS.SiteProvider;
using CMS.Helpers;
...
// Gets the form info object for the 'ContactUs' form
BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("ContactUs", SiteContext.CurrentSiteID);
// Gets the class name of the 'ContactUs' form
DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
string className = formClass.ClassName;
// Loads the form's data
ObjectQuery<BizFormItem> data = BizFormItemProvider.GetItems(className);
// Checks whether the form contains any records
if (!DataHelper.DataSourceIsEmpty(data))
{
// Loops through the form's data records
foreach (BizFormItem item in data)
{
string firstNameFieldValue = item.GetStringValue("FirstName", "");
string lastNameFieldValue = item.GetStringValue("LastName", "");
// Perform any required logic with the form field values
// Variable representing a custom value that you want to save into the form data
object customFieldValue;
// Programatically assigns and saves a value for the form record's 'CustomField' field
item.SetValue("CustomField", customFieldValue);
item.SubmitChanges(false);
}
}
UPDATE:
The example above assumes that you're using the API from within the running Kentico instance. If you want to use Kentico API (DLLs) from an external application please follow the steps I described in another answer.
You also asked about the site identifier (siteId or siteName params of the BizFormInfoProvider.GetBizFormInfo() method). They refer to the SiteInfo object in Kentico (DB table CMS_Site). You can find site name if you navigate to Site->Edit site->General->Site code name.
If you don't want to use Kentico DLLs there is another option - using Kentico REST endpoint.

sending and retrieving data to API

I have a solution with 2 projects:
Contains the API
the module where i can select data (combobox etc...)
in the second module i select the API as reference that way i should be able to use data from the first module (my API) using Mollie.Api;
The First thing i want to do is fill a combobow with all the issuers, they should be in issuers.data:
Issuers issuers = mollieClient.GetIssuers();
foreach (Issuer issuer in issuers.data)
{
comboBox1.Items.Add(issuer.name);
}
the problem i have is: mollieClient does not exist in current context
i want to fill another combobox with methods but when i try to do it how they say i should do it doesnt work:
Method methods = new Method();
methods = Mollie.Api.Method.all();
however when i do:
Mollie.Api.Method.* the helper gives me then all the possible methods at *, but how can i get them automaticly in my combobox?
The second thing is when the method and issuer is selected i want to send that data back to the API. The API should be able to proces this and send me a message back that the transaction was a succes.
It appears like you're using mollie-api-csharp. You've written mollieClient, but according to the source Mollie.Api.MollieClient should start with a capital letter.
EDIT: Looks like you're following the how-to-use tutorial from the repo.
I think you forgot to create the MollieClient instance before getting the issuers.
MollieClient mollieClient = new MollieClient();
mollieClient.setApiKey("your_api_key_here");

Add items to existing SharePoint lists by coding

I want to add items to a still existing SharePoint list by self-coding.
So I searched the internet and found a lot of information how to create lists, add items and so on..
SPWeb mySite = SPContext.Current.Web;
SPListItemCollection listItems = mySite.Lists[TextBox1.Text].Items;
SPListItem item = listItems.Add();
The coding seems easy, but where i have to put the code?
I programmed Web Parts and deployed these to my web application.
This was no problem, but here i am missing an approach.
I am using VisualStudion 2008 and SharePoint WSS 3.0
Thank you for any help.
SPWeb app = SPContext.Current.Web;
SPList ListName = app.Lists["YourListName"];
SPListItem ListItem = ListName.Items.Add();
ListItem["field1Name"] = value;
ListItem["field2Name"] = value;
ListItem.Update();
It depends on the purpose - why are you doing this?
Do you have one specific list where you (as the owner/administrator) need to create items and this has to be done only once? If yes, then you can do it with Powershell, as in this Karine Bosch's post.
If you need your users to be able to add items to list using program code, then web parts is the way to go. Then you will want to build a nice user interface for that webpart. And then you can deploy your webpart to your server, create a page in your site and add the webpart to the page.
If you need to create the new list item as soon as something else happens (for instance, a list item is created in some other list, then think of event handlers.
you are doing some modification on site ...so after that we need to update the site ..Use ListItem.update();

Categories