locked
Save the textbox value into .suo file RRS feed

  • Question

  • I have created Vspackage Toolwindow in which toolwindow consist of multiple textbox and binding some data to those textbox from the database.I want that data to persist between the visual studio sessions.

    I get to know in an article that .suo file is responsible for data persist in visual studio.Please help me how to store data into the .suo file.

    Thanks in advance.

    Friday, June 19, 2015 6:44 AM

Answers

  • Hi jnanesh,

    There're many ways to persist data for your Visual Studio extension, e.g. custom settings file, registry. If you just want to use this ToolWindow to store and restore some settings, I would recommend that you create an options page instead, save the settings just like VS IDE does.

    Walkthrough: Creating an Options Page

    DialogPage.SaveSettingsToStorage Method

    If you insist on using the ToolWindow or other extensions, you can persist some user data with IsolatedStorageFile or WritableSettingsStore.

    See the sample code in this documentation:

    Walkthrough: Using the Settings Store

    private void MenuItemCallback(object sender, EventArgs e)
            {
                SettingsManager settingsManager = new ShellSettingsManager(this);
                SettingsStore configurationSettingsStore = settingsManager.GetReadOnlySettingsStore(SettingsScope.Configuration);
                
                //bool isVisualWebDevInstalled = configurationSettingsStore.CollectionExists("InstalledProducts\\Visual Web Developer");
                //string message = "Visual Web Developer Installed: " + isVisualWebDevInstalled;
    
                //string message = "First five services:\n";
                //IEnumerable<string> collection = configurationSettingsStore.GetSubCollectionNames("Services");
                //int n = 0;
                //foreach (string service in collection)
                //{
                //    if (n++ == 5) break;
                //    message += configurationSettingsStore.GetString("Services\\" + service, "Name", "Unknown") + "\n";
                //}
    
                WritableSettingsStore userSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
                int toolCount = userSettingsStore.GetInt32("External Tools", "ToolNumKeys");
                bool hasNotepad = false;
                CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo;
                for (int i = 0; i < toolCount; i++)
                {
                    if (Compare.IndexOf(userSettingsStore.GetString("External Tools", "ToolCmd" + i), "Notepad", CompareOptions.IgnoreCase) >= 0)
                    {
                        hasNotepad = true;
                        break;
                    }
                }
    
                string message = (hasNotepad) ? "Notepad already installed" : "Installing Notepad";
                if (!hasNotepad)
                {
                    userSettingsStore.SetString("External Tools", "ToolTitle" + toolCount, "&Notepad");
                    userSettingsStore.SetString("External Tools", "ToolCmd" + toolCount, "C:\\Windows\\notepad.exe");
                    userSettingsStore.SetString("External Tools", "ToolArg" + toolCount, "");
                    userSettingsStore.SetString("External Tools", "ToolDir" + toolCount, "$(ProjectDir)");
                    userSettingsStore.SetString("External Tools", "ToolSourceKey" + toolCount, "");
                    userSettingsStore.SetUInt32("External Tools", "ToolOpt" + toolCount, 0x00000011);
    
                    userSettingsStore.SetInt32("External Tools", "ToolNumKeys", toolCount + 1);
                }
    
    
    
                // Show a Message Box to prove we were here
                IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                Guid clsid = Guid.Empty;
                int result;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                           0,
                           ref clsid,
                           message,
                           string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.ToString()),
                           string.Empty,
                           0,
                           OLEMSGBUTTON.OLEMSGBUTTON_OK,
                           OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                           OLEMSGICON.OLEMSGICON_INFO,
                           0,        // false
                           out result));
            }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Caillen Monday, June 29, 2015 3:41 PM
    Monday, June 22, 2015 9:20 AM