开发者

visual studio able to save state for multiple indivisual files not in solutions?

Often I use Visual studio to edit standalone files (开发者_高级运维not in a project). So usually I will have like say 6 files opened (3 html files, 1 css file, 2 js files etc)

And the problem is that whenever i close visual studio, I have to locate and re-open all 7 files again (which is a bother really).

Is there a way for us to like save all 7 files in a state file and simply when i open that state file it will open all the 7 files in whatever order I have last saved them as ?

If you have used Notepad++ you will know what I'm talking about, basically when we close Notepad++ and open it the files that were previously opened stay opened, some sort of functionality like this.


Here's two Visual Studio macro methods that should do exactly what you need.

SaveAll() saves all open files and writes a file named status.txt to C: in which all open files are written separated by semicolon (totally independent of project/solution):

Sub SaveAll()

    Dim text As String
    Dim i As Integer

    For i = 1 To DTE.Documents.Count
        text += DTE.Documents.Item(i).FullName + ";"
        DTE.Documents.Item(i).Save()
    Next i

    My.Computer.FileSystem.WriteAllText("C:\status.txt", text, False)

End Sub

Next time, when you want to open those files, you simply call OpenAll(). It reads the status file, splits the semicolon separated text, and opens all files:

Sub OpenAll()
    'Open status file
    Dim text As String
    text = My.Computer.FileSystem.ReadAllText("C:\status.txt")

    Dim files As String()
    files = text.Split(";")
    Dim file As String
    For Each file In files
        If file.Length > 0 Then DTE.ItemOperations.OpenFile(file)
    Next
End Sub

It's easy enough to modify this according to your needs (or even add a file dialogue). Thanks for asking this question, it made me focus on the VS macro IDE again and see how powerful it is.


You could just have a temporary or scratch solution for adding these files to, and when you've finished working on them (after days or weeks or whatever) just remove them. Solution files are probably a bit much for this, but you wouldn't have to do any extra work.

Otherwise look at making the recently opened files list a bit longer so they stay in there for longer.

Or use another editor for this purpose. I use Notepad++ for all my non-solution/non-project related files. If you close it without closing the individual files they remain in the editor next time you open it. It's faster and lighter weight than VS too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜