Posted Thu, 09 Aug 2018 12:08:05 GMT by Seth Jaco Support Specialist

I have recently been digging into the API using .NET and was wondering if there was a way to create a data record from data inside a CSV or XML file? I am able to store data + documents using the API but now I need to know if I can just store data.

 

Thanks,
Seth

Posted Thu, 09 Aug 2018 12:52:27 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

Seth,

In between you contacting me on LinkedIn and posting this, I figured it out!

Here is sample C# code to post just store data to a file cabinet:

=============================
Organization org = <reference to your organization instance from the ServiceConnection>
string cabID = lvFileCabinets.SelectedItems[0].SubItems[1].Text;
FileCabinet fileCabinet = org.GetFileCabinetById(cabID);
Document indexInfo = new Document();
indexInfo.Fields = new List<DocumentIndexField>();
indexInfo.Fields.Add(DocumentIndexField.Create("INDEXFIELD1", <index value>));
indexInfo.Fields.Add(DocumentIndexField.Create("INDEXFIELD2", <index value>));
Document uploadedDoc = fileCabinet.PostToDocumentsRelationForDocument(indexInfo);
=============================

The crucial method here is "PostToDocumentsRelationForDocument". That lets you post just index data and creates a data-onle document for you in the cabinet.

You would need to take your CSV of XML file to load up the index info document, but that should be doable in C#, too.

Good luck, hope this helps!

Thanks,
Joe Kaufman

Posted Thu, 09 Aug 2018 13:08:00 GMT by Seth Jaco Support Specialist

That is awesome, I was close but did not get the Post command correct. I will post what I have when I get it working.

Thanks,
Seth

 

EDIT: Well l was finally able to work on this for a bit and am not able to get "PostToDocumentsRelationForDocument" it is stating there is no definition for it. Digging around and will see what I can find.

Posted Thu, 09 Aug 2018 18:24:00 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

Seth,

That is a method of a FileCabinet object. If it is not displaying in Intellisense then you aren't performing the method call on a FileCabinet object. There is really no way C# code can be wrong, because it won't compile if the objects are not of the right type. Can you post some code?

 

Thanks,

Joe Kaufman

Posted Thu, 09 Aug 2018 18:54:29 GMT by Seth Jaco Support Specialist

Sure, what I have so far is a Windows form that uses a test name and password to make my connection. It then has a drop down box that populates on form load to show the available file cabinet 

==============================================================================

 var conn = ServiceConnection.Create(uri, "BasicAdmin", "admin", "TestSrv");
            Organization org = conn.Organizations[0];

            var fileCabinet = org.GetFileCabinetsFromFilecabinetsRelation().FileCabinet;
            foreach (var fc in fileCabinet)
                fCabinet.Items.Add(fc.Name);

==============================================================================

I then have a button that processes a CSV file and hopefully will insert the data to create a data record

==============================================================================

//Path for the CSV file.  
                string csvPath = @"C:\Test.csv";

                //Read the contents of CSV file.  
                string csvData = File.ReadAllText(csvPath);

                //Execute a loop over the rows.  
                foreach (string row in csvData.Split('\n'))
                {
                    //Creating array to read CSV into.
                    string[] cell = null;

                    if (!string.IsNullOrEmpty(row))
                    {
                        cell = row.Split(',');
                        int docID = Int32.Parse(cell[0]);

                        Document indexInfo = new Document();
                        indexInfo.Fields = new List<DocumentIndexField>();
                        indexInfo.Fields.Add(DocumentIndexField.Create("Contact", cell[1]));
                        indexInfo.Fields.Add(DocumentIndexField.Create("Subject", cell[2]));
                        Document uploadedDoc = fileCabinet.PostToDocumentsRelationForDocuments(indexInfo);
                    }

                }

==============================================================================

 

I hope that makes sense.

Thanks

Posted Thu, 09 Aug 2018 19:05:25 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

Seth,

In your button's click event, you cannot just reference "fileCabinet" if that variable is not in the Click event code. This is a "scope" issue. Each subroutine can only see the variables declared within it. So, unless you make "fileCabinet" a form-level member or property (that everything inside the form class can see), it will never generate any Intellisense and things will not compile. There is likely a red squiggly line under it because the design-time editor is saying, "I have no iidea what fileCabinet is in this context."

How do you display a list of available file cabinets? In other words, how does the List<string> called "fCabinet" manifest itself so you can select an actual file cabinet? Where do you load the names, and how do they display? If you just load those names in a List in one method, they are not going to be available to any other method. You need a form-level member that is a list of file cabinet GUIDs or something you can select/reference to choose the file cabinet to use. Alternately, you need a control on the form such as a ListView, as controls on the form can be references anywhere on the form since they are UI-related member classes of the form.

Once you have a real, instantiated FileCabinet object in that routine, the appropriate method will be available for it and you will be in business.

 

Thanks,

Joe Kaufman

Posted Thu, 09 Aug 2018 19:19:39 GMT by Seth Jaco Support Specialist

Gotcha, I am writing the File Cabinets to a Combox Box using the last line under the first section of code "fCabinet.Items.Add(fc.Name);"

It displays quite well

 

https://www.docuware.com/sites/default/files/forums-images/DropDown.JPG

Posted Thu, 09 Aug 2018 19:48:28 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

Seth,

Nice. You will want to store the file cabinet GUID in the combo box, too (hidden column?) or use a ListView that can have multiple columns. Then, in the button click, check the index of the combo box and get the GUID. Then you should be ready to go.

I will be around more tomorrow but am off work all weekend and next week, so hopefully you get this working by then!  *smile*

 

Thanks,

Joe Kaufman

Posted Tue, 14 Aug 2018 19:36:36 GMT by Seth Jaco Support Specialist

I was able to work on this a bit today, however, I am getting an error message "Cannot implicitly convert type String to DocuWare.Platform.ServerClient.FileCabinet. Any thoughts?

Posted Wed, 15 Aug 2018 11:31:49 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

Seth,

When you have these errors, you need to provide the code that is erroring out. There is no way to debug without seeing the line that is erroring out and the lines around it. Also, is this a compile-time or run-time error?

I am on vacation until Monday, so if you provide a sample by then I can take a look. It sounds like you are simply supplying the wrong data type to a field as you are creating the indexes for the store. Make sure all data types match what the DocuWare cabinet is expecting.

 

Thanks,

Joe Kaufman

Posted Wed, 15 Aug 2018 11:37:26 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

It also sounds like you are trying to use a string variable as a FileCabinet type, so your code seems to have some fairly serious issues...

Thanks,

Joe Kaufman

Posted Wed, 15 Aug 2018 13:51:27 GMT by Seth Jaco Support Specialist

No worries, I remember having this issues before and I cannot for the life of me remember what I did to resolve it. Here is the code that it does not like. I am taking the highlighted option, from the Listview and trying to pass it through for use of the stored document. So the user selects a File Cabinet, then when they hit a button it should store the data in the CSV file as a new data store for that File Cabinet that was selected. The error is occuring on the starred line for cabID

 

string cabID = (fCabinet.SelectedItems)["File Cabinet"].ToString(); 

*FileCabinet fileCabinet = cabID;*
Document indexInfo = new Document();
indexInfo.Fields = new List<DocumentIndexField>();
indexInfo.Fields.Add(DocumentIndexField.Create("Contact", cell[1]));
indexInfo.Fields.Add(DocumentIndexField.Create("Subject", cell[2]));
Document uploadedDoc = fileCabinet.PostToDocumentsRelationForDocuments(indexInfo);

Posted Thu, 16 Aug 2018 12:06:07 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

Seth,

You are trying to assign a string directly to a FileCabinet type. That's not going to work. A FileCabinet instance needs to be created with the "new" keyword, as in:

FileCabinet cab = new FileCabinet();

I am not sure if the constructor of FileCabinet can take a GUID string directly, but I am pretty sure it cannot. I think a file cabinet is created from an Organization object, but do not have my sample code handy until Monday.

 

Thanks,

Joe Kaufman

Posted Mon, 20 Aug 2018 12:41:52 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

Seth,

OK, I got some sample code, and I realize getting a specific file cabinet is not as easy as I thought -- I wrote some extension methods to make it easier.

Here is an extension method of an Organization object that can get you a file cabinet by it's ID:

=========================================================================================
public static FileCabinet GetFileCabinetById(this Organization org, string fileCabinetId)
{
    FileCabinet fileCabinet = null;
    if (org == null) return null;
    if (fileCabinetId.Length == 0) return null;
    List<FileCabinet> fileCabinets = org.GetFileCabinetsFromFilecabinetsRelation().FileCabinet;
    fileCabinet = fileCabinets.Where(f => f.Id.Trim().ToUpper() == fileCabinetId.Trim().ToUpper()).First();
    return fileCabinet;
}
=========================================================================================

Basically, if you put the above static method somewhere in scope (same namespace), then Intellisense will offer the method as an extension method of the Organization object. It would appear the key method built in to DocuWare is GetFileCabinetsFromFilecabinetsRelation(), but that returns all file cabinets. So, we filter the List of FileCabinet objects using LINQ. Here is the same thing, but it gets a file cabinet by name instead of GUID:

=========================================================================================
public static FileCabinet GetFileCabinetByName(this Organization org, string fileCabinetName)
{
    FileCabinet fileCabinet = null;
    if (org == null) return null;
    if (fileCabinetName.Length == 0) return null;
    List<FileCabinet> fileCabinets = org.GetFileCabinetsFromFilecabinetsRelation().FileCabinet;
    fileCabinet = fileCabinets.Where(f => f.Name.Trim().ToUpper() == fileCabinetName.Trim().ToUpper()).First();
    return fileCabinet;
}
=========================================================================================

I am not sure why DocuWare does not build in these handy methods to the package libraries, or maybe there is a better way and I just don't know it. Here is the help page on getting file cabinets, so I must have gotten my original code/idea from there:

http://help.docuware.com/sdk/platform/html/ee25973f-3c6a-456b-967d-a8b179881d3f.htm

Hope this helps!

Thanks,
Joe Kaufman

Posted Mon, 20 Aug 2018 13:43:49 GMT by Seth Jaco Support Specialist

Awesome, hopefully I can get some time later this afternoon and test. I will let you know what I find.

Thanks

Posted Mon, 20 Aug 2018 13:47:59 GMT by Joe Kaufman Bell Laboratories Inc Senior System Architect

Here is a quick link to implementing extension methods in general:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods

 

Thanks,

Joe Kaufman

You must be signed in to post in this forum.