Reply

C# open and close files with in folder code

I am looking for a code that would allow me to open and close each psm file within a given folder. I have a code that i have created to gather property information and print out what i need. i would like to add this into the open and close code. I am very slow at coding and just learning, took me 2.5 week to write what i have currently. any help would be great.

Nathan M. Gardner

https://www.etsy.com/people/NathanMGardner

Be sure to check out my work!!
Made in Maine Wood Carvings

5 REPLIES

Nathan,   Someone may beat me to an answer but I wanted t...

Nathan,

 

Someone may beat me to an answer but I wanted to mention that I'm having to write something similar (probably today) and would be happy to share when I get done.

Jason Newell
Applications Architect
www.jasonnewell.net

Hi mate,   I have done this but in VBA, not C#. Would tha...

Hi mate,

 

I have done this but in VBA, not C#. Would that help you at all? I'd be happy to help.

 

Thanks

The following C# code is iterating through all PSM files...

The following C# code is iterating through all PSM files in a given folder and dumps all Custom properties. I believe you can adopt this code to your needs.

void DumpCustomPropsOfPsmFilesInFolder(String strFolder)
{
  System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(strFolder);
  System.IO.FileInfo[] files = dirInfo.GetFiles("*.psm");
  for (int i = 0; i < files.Length; i++)
  {
    Console.WriteLine("File: {0}", files[i].FullName);
    SolidEdgeFileProperties.PropertySets propSets = new SolidEdgeFileProperties.PropertySets();
    propSets.Open(files[i].FullName, true);
    SolidEdgeFileProperties.Properties propsCustom = null;
    foreach (SolidEdgeFileProperties.Properties props in propSets)
    {
      if (props.Name == "Custom")
      {
        propsCustom = props;
        break;
      }
    }
    if (propsCustom != null)
    {
      foreach (SolidEdgeFileProperties.Property prop in propsCustom)
      {
        Console.WriteLine("  Property: {0} = {1}", prop.Name, prop.Value);
      }
    }
    propSets.Close();
  }
}

 

Re: Nathan,   Someone may beat me to an answer but I wanted t...

Jason,
I think "others" (ME) might also be interested in seeing this code if you are willing to share.
Thanks Mate!
Matt Johnson
Application Engineer
Ally PLM Solutions
matt.johnson@allyplm.com
http://allyplm.com/

Re: Nathan,   Someone may beat me to an answer but I wanted t...

I've been working on an OpenSave program tonight and have learned a lot. I'll clean it up and add it to http://solidedgesamples.codeplex.com. Should be there for the next release.
Jason Newell
Applications Architect
www.jasonnewell.net