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?
Question
Question
Answer
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);
Replies
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);
}
}
}
Script or SDK Script
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);
Care to share the code? We are trying to do the same thing!
Will post in the morning!
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) .
No, System.IO.File.Copy works with files on disk. This thread is not about exporting files from Laserfiche.