You are viewing limited content. For full access, please sign in.

Question

Question

Saving a CSV Report to a Network Drive

asked on May 22, 2017

I have a workflow that creates a CSV file and is emailed to a user. Now the user wants it run daily and placed on a network drive. What activity would I use to save the CSV file to a network drive?

3 0

Answer

SELECTED ANSWER
replied on May 22, 2017

True ... my VAR help me out. Thanks!

            // overwriting an existing file with same name

            System.IO.File.Copy(GetTokenValue("some csv path token").ToString(), @"\\machineOrIP\restofpath\filename", true);

0 0

Replies

replied on May 23, 2017

Here's what we do to generate a report to a network drive:

Write csv header:

namespace WorkflowActivity.Scripting.Writecsvheader
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using Laserfiche.RepositoryAccess;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : RAScriptClass92
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            // set a path to write to. run the workflow on a schedule and overwrite the file

            string fpath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),@"LaserficheReports\\WFReports\\");
                //  This path converts to C:\ProgramData\LaserficheReports\WFReports\CSEL
            if(!System.IO.Directory.Exists(fpath))
                System.IO.Directory.CreateDirectory(fpath);
            fpath = System.IO.Path.Combine(fpath, "CSELReport.csv");

            // create a token or update one if you added an Assign Tokens activity
            SetTokenValue("csvpath", fpath);

            // best to use full csv unless you are absolutely certain that the values will not have any special characters like comma and double quotes

            System.IO.File.WriteAllText(fpath, "\"Entry ID\",\"Status\",\"Doc ID\",\"Document #\",\"Revision\",\"Vendor Document #\",\"Software Code\",\"Document Date\",\"Date Last Updated\",\"Notes\"" + Environment.NewLine);

            // done with file prep

        }
    }
}

Write each document to file:

namespace WorkflowActivity.Scripting.Writeeachdocumenttofile
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using Laserfiche.RepositoryAccess;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : RAScriptClass92
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            // generate the line with full csv
            string s = "\"" + GetTokenValue("ForEachEntry_CurrentEntry_ID") + "\"";
            s += ",\"" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_Status")) + "\"";
            s += ",\"" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_Doc ID")) + "\"";
            s += ",\"" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_Document #")) + "\"";
            s += ",\"'" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_Revision")) + "\"";
            s += ",\"" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_Vendor Document #")) + "\"";
            s += ",\"" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_Software Code_1")) + "\"";
            s += ",\"" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_Document Date")) + "\"";
            s += ",\"" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_LastModifiedDate")) + "\"";
            s += ",\"" + FixValue(GetTokenValue("ForEachEntry_CurrentEntry_Notes")) + "\"";

            System.IO.File.AppendAllText(GetTokenValue("csvpath").ToString(), s + Environment.NewLine);
        }

        private string FixValue(object o)
        {
            if(o == null)
                return "";
            else
                return o.ToString().Replace("\"", "\"\""); // make sure properly escaped
        }
    }
}

Write csv file to network drive:

namespace WorkflowActivity.Scripting.Writecsvfiletonetworkdrive
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using Laserfiche.RepositoryAccess;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : RAScriptClass92
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {
            // overwriting existing file with same name
            System.IO.File.Copy(GetTokenValue("csvpath").ToString(), @"\\[YourNetworkDrive]\Design Engineering Dashboard data\CSELReport.csv", true);
        }
    }
}

 

3 0
replied on July 24, 2018

Thank you. This was very helpful.

0 0
replied on May 22, 2017

Script or SDK Script

0 0
SELECTED ANSWER
replied on May 22, 2017

True ... my VAR help me out. Thanks!

            // overwriting an existing file with same name

            System.IO.File.Copy(GetTokenValue("some csv path token").ToString(), @"\\machineOrIP\restofpath\filename", true);

0 0
replied on May 22, 2017

Care to share the code? We are trying to do the same thing!

0 0
replied on May 22, 2017

Will post in the morning!

0 0
replied on July 5, 2017 Show version history

System.IO.File.Copy(GetTokenValue("some csv path token").ToString(), @"\\machineOrIP\restofpath\filename", true);

"some csv path token" is the %(FindEntry_OutputEntry_FullPath) of the svc in Repository ?

when i change to a fullpath Token

 

System.IO.File.Copy(GetTokenValue("OutputEntry_FullPath").ToString(), @"\\machineOrIP\restofpath\filename", true); 

that get a err about "Could not find a part of the path '\data source\data' (the svc path in Repository) .

0 0
replied on July 6, 2017

No, System.IO.File.Copy works with files on disk. This thread is not about exporting files from Laserfiche.

1 0
replied on May 22, 2017

Care to share the method you used or the code? We are trying to do the same thing!

0 0
replied on May 22, 2017

Will do so in the morning.

0 0
replied on May 30, 2017

Thank you, I appreciate the help!

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.