// Obtain the service provider for the current project IServiceProvider serviceProvider = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsServiceProvider)) as IServiceProvider; // Get the current project IVsProject project = SolutionHelper.GetActiveProject(serviceProvider); // Get the document path for the current item in the project string documentPath = string.Empty; if (project != null) { int result = project.GetMkDocument(0, out documentPath); }
public static void GetDocumentPathForItem(IVsProject project, string itemName) { int result = project.GetItemInfo(itemName, 0, out uint itemId, IntPtr.Zero, out uint itemStatus, out IntPtr itemNamePtr); string itemPath = string.Empty; if (result == VSConstants.S_OK) { result = project.GetMkDocument(itemId, out itemPath); } Marshal.FreeBSTR(itemNamePtr); }In this example, we define a method that takes an IVsProject instance and an item name as input. We use the GetItemInfo() method to get the ID and status of the item in the project, and then use the GetMkDocument() method to get the document path for that item. Package library: Microsoft.VisualStudio.Shell.Interop.