Cancel
Showing results for 
Search instead for 
Did you mean: 

Teamcenter SOA and C#: How to download a file?

Pioneer
Pioneer

Hi!

 

I am fresh to Teamcenter and just beginning my journey here. I have a connection open with TCUA in my code. I can few files in the system but am not sure how to use download files. I tried using WebClient and its downloading unusable 4kb files. I as well don't know how the FileManagementUtility is used to download a file from the db to my system.

 

I found a few referenced posts with very similar questions:

Soa Download File

Download file link 2

 

However, none of the answers go about explaining how to do this or link to a page that does.

 

Any help or links to pages with information on this process are greatly appreciated.

7 REPLIES

Re: Teamcenter SOA and C#: How to download a file?

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

Re: Teamcenter SOA and C#: How to download a file?

Pioneer
Pioneer

So this looks like its for downloading portions of a dataset. What if I want to download a single specific file? I see DownloadFileFromPLM() & DownloadFiletoLocation().

 

I have the files Uid and Object_string properties. Rather what I should say is I don't know how to get the ImanFile.

 

When I try to obtain any of the "IMAN" properties I can see, it returns:

The IMAN_Rendering property is not loaded in the client model.

 

The other two properties are IMAN_based_on and IMAN_external_object_link.

Re: Teamcenter SOA and C#: How to download a file?

Solution Partner Legend Solution Partner Legend
Solution Partner Legend
All properties won't be loaded by default. You have to set a property policy (it's explained in the doc) and add the required properties in the defined policy. This can be done in code or policy xml. Sample policy xml are in %TC_DATA%\soa\policies\Default.xml

Re: Teamcenter SOA and C#: How to download a file?

Pioneer
Pioneer

I have the tc_data/soa/policies/Default.xml open, but this doesn't necessarily translate on how to do this for my c# solution. How do I set a property policy in c# via code or do I need an xml doc such as this included in the project?

Re: Teamcenter SOA and C#: How to download a file?

Pioneer
Pioneer

UPDATE TWO

Created new topic that better suited the question

 

UPDATE
Tried

FileManagementUtility fmu = new FileManagementUtility(Teamcenter.ClientX.Session.getConnection());
fmu.GetFileToLocation(stl, "C:/Users/jtth/Desktop/TestFolder/" + stl.Object_string, null, null);

Returned

Exception thrown: 'System.IO.FileNotFoundException' in TcSoaClient.dll
Exception thrown: 'System.NullReferenceException' in TcSoaClient.dll
Object reference not set to an instance of an object.

 

Re: Teamcenter SOA and C#: How to download a file?

Experimenter
Experimenter

Could you please share any sample code to dowanlaod uding SOA.

Thanks a lot.

Re: Teamcenter SOA and C#: How to download a file?

Experimenter
Experimenter
public void pullFiles()
{
    //  foreach file inside of yourFolderNameOnTeamcenter
    //      download the files into a folder on your computer

    try
    {
        // Initialize and get yourFolderNameOnTeamcenter contents
        WorkspaceObject[] folderContents;
        folderContents = Folders.GetFolderContents(yourFolderNameOnTeamcenter);

        foreach (ModelObject mo in folderContents)
        {
            if (mo == null)
                return;

            /* cast from ModelObject to Dataset.
                * necessary to acquire the Object_string
                * and Ref_list properties */
            Dataset ds = ((Dataset)mo);

            /* create destination path */
            string destinationFilePath = "C://folderNameToDownloadFileTo/" + ds.Object_string;

            try
            {
                Console.WriteLine("==================================================================");

                ModelObject file = ds.Ref_list[0];


            // IN ORDER TO DOWNLOAD YOUR FILE USING THE 'FILE MANAGEMENT UTILITY' YOU MUST CREATE IT
            /* EX:                 
                Create FileManagementUtility (FMU)
                FileManagementUtility fileUtility = new FileManagementUtility(TeamcenterConnection);
            */
                GetFileResponse res = fileUtility.GetFileToLocation(
                    file, destinationFilePath, null, null);

                System.IO.FileInfo[] files = res.GetFiles();

                Console.WriteLine("fileLen: " + files.Length);
                Console.WriteLine("fileName: " + files[0].FullName);

                for (int j = 0; j < files.Length; j++)
                {
                    String path = files[j].FullName;
                    Console.WriteLine("filePath: " + path);
                }

                Console.WriteLine("==================================================================");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

 

 

Veering off the FMU tickets route of downloading datasets (files), it became apparent an easier solution was to acquire a reference to the Teamcenter folder containing any/all files we wanted to download and access them this way.

 

A couple of notes: you must have an active Teamcenter connection to use both the File Management Utility, and to obtain yourFolderNameOnTeamcenter reference. An example of how to acquire the folder reference is below.

 

Folder TeamcenterMainFolder = Folders.GetSubfolder(TeamcenterConnection.HomeFolder, "Teamcenter Main Folder Name");

Folder yourFolder = Folders.GetSubfolder(TeamcenterMainFolder, "yourFolderNameOnTeamcenter");