I'm working on my first Visual Studio
extension. I managed to setup event listener when a file is saved and modify another file using DocData
on this way:
var docData = new DocData(this, fileName);
var editorAdaptersFactoryService = (this.GetService(typeof(SComponentModel)) as IComponentModel).GetService<IVsEditorAdaptersFactoryService>();
var textBuffer = editorAdaptersFactoryService.GetDataBuffer(docData.Buffer);
textBuffer.Replace(new Span(0, textBuffer.CurrentSnapshot.Length), content);
The problem here is that after I modify this new file I have to save it but I couldn't find any examples about how to save a file. Inside my DocumentSaved
listener I have a EnvDTE.Document
where I can call EnvDTE.Document.Save()
but I'm trying to save another file, I have the full path of this new file I'm trying to save. I though about iterating over all the files in the project looking for my specific file and there use the available Save()
method in ProjectItem
. I tried using the code in this answer but it didn't work.
Any guidance on this would be great!