Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 854501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:56:00+00:00 2026-05-15T07:56:00+00:00

Can you save an object to a settings.settings file in Visual Studio? If so

  • 0

Can you save an object to a settings.settings file in Visual Studio? If so how? I think you can make your object serializable and it should persist, but I’m not sure if I’m doing it right i.e. when I try to get the object back it is always null.

Here is the code:

    [Serializable()]
    [XmlRoot(ElementName = "LayerTCA", IsNullable = false, Namespace = "http://somesite.com")]
    public class LayerTCA
    {
        //This is a COM object so I don't want to serialize this.
        IFeatureClass featureClass;

        string fullName;
        string basicName;

        public LayerTCA()
        {

        }

        public LayerTCA(IFeatureClass featureClass)
        {
            FeatureClass = featureClass;
        }


        public IFeatureClass FeatureClass
        {
            get { return featureClass; }
            set 
            {
                featureClass = value;
                fullName = featureClass.AliasName;
                basicName = StringHelper.StringAfterLastFullStop(fullName);
            }
        }

        [XmlAttribute(AttributeName = "BasicName")]  
        public string BasicName
        {
            get { return basicName; }
            set { basicName = value; }
        }


        [XmlAttribute(AttributeName = "FullName")]  
        public string FullName
        {
            get { return fullName; }
            set { fullName = value; }
        }

        public override string ToString()
        {
            return FullName;
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:56:01+00:00Added an answer on May 15, 2026 at 7:56 am

    I’d use a member variable that is an IFeatureClassName. The constructor would accept an IFeatureclass, then cast the featureclass to IDataset and set the member variable to IDataset.FullName. This will be an IName. All IName objects are persistable via IPersistStream. While not directly serializable to xml, an IPersistStream object can be written to a byte[] (via MemoryBlobStream). Can’t remember if byte[] can be exposed via XmlAttribute, probably should use base64. Might also have an Open method would simply call IName.Open on the contained member featureclassname variable, returning an IFeatureclass.

    Update: Here’s some code that might help converting a featureclassname to and from a string.

    public static void TestIt(IFeatureClass fc)
    {
        string guidplusbase64Name = GetFullName((IDataset)fc);
        Debug.Print(guidplusbase64Name);
        IFeatureClass fc2 = OpenDataset(guidplusbase64Name) as IFeatureClass;
        Debug.Print(fc2.AliasName);            
    }
    
    public static string GetFullName(IDataset ds)
    {
        IPersistStream ps = ds.FullName as IPersistStream;
        Guid g;
        ps.GetClassID(out g);            
        IMemoryBlobStream mbs = new MemoryBlobStreamClass();
        ps.Save(mbs,0);
        object bytes;
        ((IMemoryBlobStreamVariant)mbs).ExportToVariant(out bytes);            
        return String.Format("{0};{1}",g,Convert.ToBase64String((byte[])bytes));
    }
    
    public static IDataset OpenDataset(string guidplusbase64Name)
    {
        int idx = guidplusbase64Name.IndexOf(";");
        string base64Name = guidplusbase64Name.Substring(idx+1);
        string guidString = guidplusbase64Name.Substring(0, idx);
    
        byte[] bytes = Convert.FromBase64String(base64Name);
        IMemoryBlobStream mbs = new MemoryBlobStreamClass();
        ((IMemoryBlobStreamVariant)mbs).ImportFromVariant(bytes);
        Type t = Type.GetTypeFromCLSID(new Guid(guidString));
        IName n = Activator.CreateInstance(t) as IName;
        ((IPersistStream)n).Load(mbs);
        IDataset ds = n.Open() as IDataset;
        return ds;
    }
    

    (updated to work with any IDataset, not just featureclasses)
    (update2: concatenating the clsid allows it to work with any dataset, previous version was hardwired for featureclassname)

    Don’t ask me why ESRI hasn’t gotten around to implementing IName.NameString.

    The NameString property is reserved
    for future use. When implemented, it
    will return a string representation of
    the locational component of the name
    object that may be persisted by
    applications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can do that file-by-file with Save As Encoding in Visual Studio, but I'd
You can save a SQL Server 2000 DTS package as a VB .BAS file.
Internet Explorer can save its content as an MHTML file using the Save As...
Are there any Java VMs which can save their state to a file and
I can reset FPU's CTRL registers with this: http://support.microsoft.com/kb/326219 But how can I save
In Flash, I can prompt the user for a location to save a file
Can I save page pictures from GreaseMonkey script directly to my hard drive? Is
how can I save a java applet from a website so I can run
I am working on a GUI (OpenG Builder). How can I merge the Save
Can somebody point me to a resource that explains how to go about having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.