Activated Solution on Sharepoint 2010 is not visible - sharepoint

I have activated a WSP file which includes a website template. This works and I can see the solution int he solution gallery. When I try to create a website, based on that template, its not showing up. But it says "Status: Activated".
Then I tried to deactivate it and activate it again manually. Out of a sudden, there is a new template showing up, which takes the name of my template appended by a "2".
So whats happening here exactly? The code to activate my solution is:
System.IO.MemoryStream input = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(rootDirectory + "\\Templates\\Project.wsp"), true);
SPDocumentLibrary solutionGallery = (SPDocumentLibrary)web.Site.GetCatalog(SPListTemplateType.SolutionCatalog);
try
{
SPFile solutionFile = solutionGallery.RootFolder.Files.Add("Project.wsp", input);
SPUserSolution newUserSolution = web.Site.Solutions.Add(solutionFile.Item.ID);
}
catch { ... }

Ok, I found the answer myself and want to share it here. The solution is, not to provide the solution in the catalog, but also to enable the features! It works like this:
System.IO.MemoryStream input = new System.IO.MemoryStream(System.IO.File.ReadAllBytes(rootDirectory + "\\Templates\\Project.wsp"), true);
SPDocumentLibrary solutionGallery = (SPDocumentLibrary)web.Site.GetCatalog(SPListTemplateType.SolutionCatalog);
try
{
SPFile solutionFile = solutionGallery.RootFolder.Files.Add("Project.wsp", input);
SPUserSolution newUserSolution = web.Site.Solutions.Add(solutionFile.Item.ID);
Guid solutionId = newUserSolution.SolutionId;
SPFeatureDefinitionCollection siteFeatures = web.Site.FeatureDefinitions;
var features = from SPFeatureDefinition f
in siteFeatures
where f.SolutionId.Equals(solutionId) && f.Scope == SPFeatureScope.Site
select f;
foreach (SPFeatureDefinition feature in features)
{
try
{
web.Site.Features.Add(feature.Id, false, SPFeatureDefinitionScope.Site);
}
catch { }
}
SPWebTemplateCollection webTemplates = web.Site.RootWeb.GetAvailableWebTemplates(1033);
SPWebTemplate webTemplate = (from SPWebTemplate t
in webTemplates
where t.Title == "Projekt"
select t).FirstOrDefault();
if (webTemplate != null)
{
try
{
web.Site.RootWeb.ApplyWebTemplate(webTemplate.Name);
}
catch { }
}
}
catch { ... }

Related

Microsoft.Azure.CognitiveServices.Search.EntitySearch.EntitySearchClient.Entities.Search(location: <latitude>:? <longitude>:?

I'm running the Microsoft sample for Bing Entity Search using the SDK and (NOT the REST API.) I can.t figure out how to enter the location key/value pair, based on this documentation:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.cognitiveservices.search.entitysearch.entitiesoperationsextensions.search?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(Microsoft.Azure.CognitiveServices.Search.EntitySearch.EntitiesOperationsExtensions.Search);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.7.2);k(DevLang-csharp)%26rd%3Dtrue&view=azure-dotnet
I would like to continue to use named parameters so I can still do this:
var restaurants = client.Entities.Search(query: currentQuery, location: lat:? long:?);
The method with the query and location from the Microsoft sample will look like this:
public static void MultipleCurrentQueryLookup(string subscriptionKey)
{
var client = new EntitySearchClient(new ApiKeyServiceClientCredentials subscriptionKey));
try
{
string currentQuery = Settings1.Default.CurrentQuery;
var restaurants = client.Entities.Search(query: currentQuery,
location: "lat:47.623, long:-122.361, re:380m");
if (restaurants?.Places?.Value?.Count > 0)
{
// get all the list items that relate to this query
var listItems = restaurants.Places.Value.Where(thing => thing.EntityPresentationInfo.EntityScenario == EntityScenario.ListItem).ToList();
if (listItems?.Count > 0)
{
var sb = new StringBuilder();
foreach (var item in listItems)
{
var place = item as Place;
if (place == null)
{
Console.WriteLine("Unexpectedly found something that isn't a place named \"{0}\"", item.Name);
continue;
}
sb.AppendFormat(",{0} ({1}) {2}", place.Name, place.Telephone, place.Url);
}
Console.WriteLine("Ok, we found these places: ");
Console.WriteLine(sb.ToString().Substring(1));
}
else
{
Console.WriteLine("Couldn't find any relevant results for \"The Current Query\"");
}
}
else
{
Console.WriteLine("Didn't see any data..");
}
}
catch (ErrorResponseException ex)
{
Console.WriteLine("Encountered exception. " + ex.Message);
}
}

Pdf jumps to page 2 when opening

I used the C# sample of PDFViewSimpleTest
When opening a pdf, it automatically jumps to the second page.
Foxit does it too (so i guess they also use pdfTron), Adobe starts from page 1
I haven't got a clue why. The pdf can be found here: http://docdro.id/EDsbCcH
The code is really simple:
public bool OpenPDF(String filename)
{
try
{
PDFDoc oldDoc = _pdfview.GetDoc();
_pdfdoc = new PDFDoc(filename);
if (!_pdfdoc.InitSecurityHandler())
{
AuthorizeDlg dlg = new AuthorizeDlg();
if (dlg.ShowDialog() == DialogResult.OK)
{
if(!_pdfdoc.InitStdSecurityHandler(dlg.pass.Text))
{
MessageBox.Show("Incorrect password");
return false;
}
}
else
{
return false;
}
}
_pdfview.SetDoc(_pdfdoc);
_pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_page);
filePath = filename;
if (oldDoc != null)
{
oldDoc.Dispose();
}
}
catch(PDFNetException ex)
{
MessageBox.Show(ex.Message);
return false;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
this.Text = filename; // Set the title
return true;
}
Technically you can achieve by an OpenAction inside the Catalog directory of the PDF, that a PDF opens at a page, which is not the first page. But that isn't the case in your PDF. The PDF itself seems to be very trivial, without anything special.
My Foxit Reader version 8.2.1 does open this PDF normally at the first page.
Please try the latest version.
Official: https://www.pdftron.com/pdfnet/downloads.html
Nightly Stable/Production: http://www.pdftron.com/nightly/?p=stable/

Rename a snapshot in Hyper-V WMI V2 from C#

I am trying to rename a Hyper-V snapshot (checkpoint) using root\virtualization\v2. None of the standard methods like ModifySystemSettings or ModifyVirtualSystem of Msvm_VirtualSystemSnapshotService or Msvm_VirtualSystemManagementService has been helpful so far.
Powershell Rename-VMSnapshot can do the job however I am not sure it is using WMI.
Any idea?
Here is what worked for me:
//
// Rename last snapshot to desired name
//
using (ManagementBaseObject inParams = vmms.GetMethodParameters("ModifySystemSettings"))
{
ManagementObject setting = null;
ManagementObjectCollection settings = vm.GetRelated(
"Msvm_VirtualSystemSettingData",
"Msvm_MostCurrentSnapshotInBranch",
null,
null,
"Dependent",
"Antecedent",
false,
null
);
foreach (ManagementObject instance in settings)
{
// Usually only one, but loop through to the end to get latest one
if (setting != null)
{
if (string.Compare(
(string)instance["CreationTime"],
(string)setting["CreationTime"],
true) > 0
)
{
// Get latest one since there could be duplicates
setting = instance;
}
}
else
{
setting = instance;
}
}
setting["ElementName"] = snapshotName;
inParams["SystemSettings"] = setting.GetText(TextFormat.WmiDtd20);
using (ManagementBaseObject outParams = vmms.InvokeMethod("ModifySystemSettings", inParams, null))
{
// What this does is get Job managementObject and check JobState to be JobCompleted.
this.ProcessSnapshotMethodResult(outParams, "rename");
}
}

Outlook : Conflict while saving contact

I am working on a project involving contact synchronization between Outlook and SharePoint. Though there is an out of the box solution provided for this by Microsoft, but it does not cater some specific requirements like custom column synchronization.
For this requirement we had to create an outlook add-in. This add-in handles ItemAdd and ItemChange event for the contact folder created as a result of the synchronization.
In the ItemChange event I check a flag in the Notes field and identify whether the change has been made from SharePoint or Outlook and accordingly update the contact item.
Here is the code for my ItemChange event.
void Items_ItemChange(object Item)
{
try
{
ContactItem ctItem = Item as Outlook.ContactItem;
string customFieldsAndFlag = ctItem.Body;
Dictionary<string, string> customColumnValueMapping = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(customFieldsAndFlag))
{
string[] flagAndFields = customFieldsAndFlag.Split(';');
if (flagAndFields.Length == 2)
{
//SharePoint to Outlook
if (flagAndFields[0] == "1")
{
foreach (string customColumnAndValue in flagAndFields[1].Split('|'))
{
string[] KeyAndValue = customColumnAndValue.Split('=');
if (KeyAndValue.Length == 2)
{
if (ctItem.UserProperties[KeyAndValue[0]] == null)
{
ctItem.UserProperties.Add(KeyAndValue[0], OlUserPropertyType.olText, true, OlUserPropertyType.olText);
ctItem.UserProperties[KeyAndValue[0]].Value = KeyAndValue[1];
}
else
{
ctItem.UserProperties[KeyAndValue[0]].Value = KeyAndValue[1];
}
}
}
ctItem.Body = "2;" + flagAndFields[1];
}
//Outlook to SharePoint
else
{
foreach (string customColumnAndValue in flagAndFields[1].Split('|'))
{
string[] KeyAndValue = customColumnAndValue.Split('=');
if (KeyAndValue.Length == 2)
{
if (ctItem.UserProperties[KeyAndValue[0]] != null && ctItem.UserProperties[KeyAndValue[0]].Value != null)
{
KeyAndValue[1] = ctItem.UserProperties[KeyAndValue[0]].Value.ToString();
}
customColumnValueMapping.Add(KeyAndValue[0], KeyAndValue[1]);
}
}
string newBody = string.Empty;
foreach (KeyValuePair<string, string> kvp in customColumnValueMapping)
{
newBody += kvp.Key + "=" + kvp.Value + "|";
}
if (newBody == flagAndFields[1])
{
return;
}
else
{
ctItem.Body = "0;" + newBody;
}
}
}
}
ctItem.Save();
}
catch(System.Exception ex)
{
// log the error always
Trace.TraceError("{0}: [class]:{1} [method]:{2}\n[message]:{4}\n[Stack]:\n{5}",
DateTime.Now, // when was the error happened
MethodInfo.GetCurrentMethod().DeclaringType.Name, // the class name
MethodInfo.GetCurrentMethod().Name, // the method name
ex.Message, // the error message
ex.StackTrace // the stack trace information
);
// now display a friendly error to the user
MessageBox.Show("There was an application error, you should save your work and restart Outlook.",
"TraceAndLog",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
Now the issue is, the contact item update works fine from outlook the first time. The contact gets updated properly, the add-in works fine and changes get reflected in SharePoint just fine. But when I try to edit the contact again using outlook, a pop-up comes up saying "Item cannot be changed because it was changed by another user or in another window. Do you want to make a copy in the default folder for the item?" and the oulook add-in stops working thereafter.
Can anyone please suggest a solution for this problem?
I cannot use ctItem.Close() as when I use this function, the synchronization process doesn't work and the changes don't get populated to SharePoint.

MonoTouch Dialog elements are not updating/repainting themselves

I have the following in a Section:
_favElement = new StyledStringElement (string.Empty);
_favElement.Alignment = UITextAlignment.Center;
if (_room.IsFavourite) {
_favElement.Image = UIImage.FromBundle ("Images/thumbs_up.png");
_favElement.Caption = "Unmark as Favourite";
} else {
_favElement.Image = null;
_favElement.Caption = "Mark as Favourite";
}
_favElement.Tapped += favElement_Tapped;
Then when I press the element I want the following to happen:
private void favElement_Tapped ()
{
if (_room.IsFavourite) {
_favElement.Image = null;
_favElement.Caption = "Mark as Favourite";
} else {
_favElement.Image = UIImage.FromBundle ("Images/thumbs_up.png");
_favElement.Caption = "Unmark as Favourite";
}
_room.IsFavourite = !_room.IsFavourite;
}
However the image and text does not change in the actual element when the element is tapped. Is there a refresh method or something that must be called? I've also tried changing the Accessory on Tapped as well and nothing changes. The properties behind do reflect the correct values though.
An alternative to reloading the UITableView is to reload the Element using code like this (copied from Touch.Unit):
if (GetContainerTableView () != null) {
var root = GetImmediateRootElement ();
root.Reload (this, UITableViewRowAnimation.Fade);
}
assuming that your code is in DialogViewController,add this
this.ReloadData();
but in your case I recommend you to use BooleanImageElement

Resources