Someone knows how can we programmatically create a Root Folder in the calendar section of Outlook 2010/2013. I only can create a subfolder in my personnal calendar root folder but can't create an another root folder.
private void EnsureRootFolderExists()
{
bool create = false;
Folder rootStoreFolder = _app.Session.DefaultStore.GetRootFolder() as Folder;
try {
_rootFolder = rootStoreFolder.Folders["Owncloud"] as Folder;
}
catch {
create = true;
}
if (create) {
_rootFolder = rootStoreFolder.Folders.Add("Owncloud") as Folder;
}
else {
_rootFolder = rootStoreFolder.Folders["Owncloud"] as Folder;
}
}
I tried this too but it create a folder in the inbox section. Not really what i search for ...
Try to specify the type of folder.
The first parameter of the Add function accepts a string which contains the display name of the new folder. The second parameter accepts the OlDefaultFolders enumeration that indicates the type of folder you want to create. If the new folder type is not specified, it will default to the type of the folder in which it is created. The following values are possible for the second parameter: olFolderCalendar, olFolderContacts, olFolderDrafts, olFolderInbox, olFolderJournal, olFolderNotes and olFolderTasks.
I agree with you. But if i do like this it will create a subfolder in the olFolderCalendar which is the default calendar folder. I would like to be able to create an another root folder in the Calendar section. It's possible to do it trough the interface (right click : New calendar group). This what il would like to achieve but programmatically.
Related
When I iterate through all Outlook folders (in a C# Add-In) I see folder names like:
Yammer Root
Sync Issues
Subscriptions
These folders are not visible in Outlook. I like to check in my code if the folder is visible or not but I don't find a property like Hidden or Visible.
MAPIFolder folder has properties like:
folder.DefaultItemType
folder.Name
but not hidden.
How can I find out in my c# Add-In if folders are hidden or not?
You will need to read the PR_ATTR_HIDDEN MAPI property (DASL name http://schemas.microsoft.com/mapi/proptag/0x10F4000B). You can read it using MAPIFolder.PropertyAccessor.GetProperty.
You can see that (and other) property using OutlookSpy (I am its author) - click IMAPIFolder button.
At least on my machine I never retrieved a value for PR_ATTR_HIDDEN for all folders. I could not find out the reason although in OutlookSpy the value is true for the hidden folders.
Code:
var rootFolder = outlook.Session.DefaultStore.GetRootFolder();
foreach (Folder folder in rootFolder.Folders)
{
try
{
bool isHidden = folder.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10F4000B");
// never reach this line
}
catch (System.Exception ex)
{
// always exception: value is not available
}
}
My workaround: If you want to retrieve the folders as they are displayed in Outlook you can use PR_CONTAINER_CLASS_W and compare it with IPF.Note or IPF.Imap.
Sample:
const string PR_CONTAINER_CLASS_W = "http://schemas.microsoft.com/mapi/proptag/0x3613001F";
string containerClass = folder.PropertyAccessor.GetProperty(PR_CONTAINER_CLASS_W);
bool isVisible = string.Equals(containerClass, "IPF.Note")|| string.Equals(containerClass, "IPF.Imap");
I'm trying to rename a branch programaticly using "PendRename" method from Microsoft.TeamFoundation.VersionControl.Client.
Moves working, so, if I use this to move everything to a new location, it works, but what I need is to rename a branch.
It is possible to do this by commandline "tfs.exe rename " (even this is given me errors if I have more than one workspace mapped for the same server url. the ... could not be found in your workspace, or you do not have permission to access it.)
So, could you please help to understand why rename a branch is not working?
Thank you,
To Rename or move files and folders in TFVC, you must be one of the Contributors for your team project. See Team Foundation Server default groups, permissions, and roles.
I tested that and renamed the branch correctly with the "PendRename" method.
Below code sample for your reference:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace RenameBranch
{
class Program
{
static void Main(string[] args)
{
string oldPath = #"E:\andy\0418Scrum\web0418-0823";
string newPath = #"E:\andy\0418Scrum\web0418-1020";
string collection = #"http://server:8080/tfs/DefaultCollection";
var tfsServer = new Uri(collection);
var tpc = new TfsTeamProjectCollection(tfsServer);
var vcs = tpc.GetService<VersionControlServer>();
Workspace workspace = vcs.GetWorkspace("YourWorkspaceName", vcs.AuthorizedUser);
workspace.PendRename(oldPath, newPath);
}
}
}
Then you need CheckIn it of course. Use a "workspace.GetPendingChanges()" and "workspace.CheckIn()" methods to do it.
Thank you,
The problem was, there are different processes that are generating workspaces to the directory, and then, he can't remove it.
So, I solve this issue doing this steps:
1. reserve a workspace local location for my appĀ“
2. see if this workspace is mapped. If yes, I remove it
3. create a workspace to the previous folder in path and create the map
4. get latest
5. rename
Thank you Andy-MSFT for your support.
Let's say we have a solution in TFS Source Control which has already been mapped to a local folder SolutionFolder.
We are in a sub folder SubFolder of this SolutionFolder.
How can we write C# code to get the mapped path of this SubFolder?
Use the WorkStation.Current to grab the information for the folder in question:
Import the following namespaces:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
and then use you can get to the data you want through:
var workspace = Workstation.Current.GetLocalWorkspaceInfo(solutionFolder);
if (workspace != null)
{
var teamProjectUri = workspace.ServerUri;
// var server = TfsConfigurationServerFactory.GetConfigurationServer(teamProjectUri);
var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(teamProjectUri);
var cssService = projectCollection.GetService<ICommonStructureService4>();
var project = cssService.GetProjectFromName(solutionName);
}
From there you can easily grab the Workspace as well and from there the serverpath: workspace.GetWorkspace().GetServerItemForLocalItem()
To provide credentials, you can use one of the additional overloads that accepts a CredentialsProvider. The default provider is the UICredentialsProvider. Or you can also call server or projectCollection's EnsureAuthenticated.
See also:
https://jessehouwing.net/vsts-tfs-api-auto-detect-connection-details/
I have created a context shell menu for / on .txt files.
Its 'action' is similar to that of 'Edit with notepad' option.
I am able to open 'notepad' on clicking the menu using this code -
subKey.SetValue("", "C:\\Windows\\System32\\notepad.exe");
//subKey is the newly created sub key - The key creation part works fine.
How will I be able to use a feature similar to that of the 'Edit with notepad' feature? Or is it at least possible to get the name of the '.txt' file on which this event was triggered?
Note: By 'Edit with notepad', I mean viewing the selected file's contents in notepad.
The shell (explorer.exe) will substitute %1 with the file name. So you basically write:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\txtfile\shell\openwithnotepad]
#="Open with &Notepad"
[HKEY_CLASSES_ROOT\txtfile\shell\openwithnotepad\command]
#="\"C:\\Windows\\System32\\notepad.exe\" \"%1\""
The file name will be passed to C:\Windows\System32\notepad.exe as a command line argument. For example if you open D:\blah.txt, then notepad will receive D:\blah.txt as the first argument.
In C#, you basically use either Environment.GetCommandLineArgs() or args in Main to retrieve the file path.
An example:
string[] commandLineArgs = Environment.GetCommandLineArgs();
string fileToOpen = null;
if (commandLineArgs.Length > 1)
{
if (File.Exists(commandLineArgs[1]))
{
fileToOpen = commandLineArgs[1];
}
}
if (fileToOpen == null)
{
// new file
}
else
{
MyEditor.OpenFile(fileToOpen);
}
With Following code I am able to add new files to visual studio project.
DTE dte = GetService(typeof(DTE)) as DTE;
System.Array theProjects = (System.Array)dte.ActiveSolutionProjects;
EnvDTE.Project theProject = null;
if (theProjects.Length > 0)
{
theProject = (EnvDTE.Project)(theProjects.GetValue(0));
EnvDTE.ProjectItem projItem = null;
projItem = theProject.ProjectItems.AddFromFile(#"E:\Avinash\test.cpp");
}
But if i have to add a header file, how do i add it under header label.
If I correctly understand what you are trying to do, I think you mean that you want to add your header files in the header folder. If it's already there you have to look for it among the items for your project. I.e. you have to loop looking for the ProjectItem with the name you are looking for. If it's not already there, you can add it using the AddFolder of ProjectItemsCollection, which returns the newly created ProjectItem. In either case you end up with a ProjectItem representing the headers folder. Now you can add your file to the ProjectItems of this object instead of the ProjectItems of the Project. Something like this:
theProject = (EnvDTE.Project)(theProjects.GetValue(0));
EnvDTE.ProjectItem projItem = null;
EnvDTE.ProjectItem hdrProjItem = theProject.ProjectItems.AddFolder("Header files", null);
projItem = hdrProjItem.ProjectItems.AddFromFile(#"E:\Avinash\test.cpp");
Anyway, I still think a template could avoid you much effort and pain