I am trying to use an Invoke Code task to execute C# code but I’m having an issue as I get an error stating that there is no compiled code to run. Any ideas on how I can get this code to compile in UiPath Studio? I’m not sure what is missing/incorrect.
Below is the code, the goal of which is to split a large file into smaller file by row count. All of the arguments needed are correctly passed to it via the Argument panel.
String inputfile = inputFileName;
String outpath = outputPath;
int linesPerFile = numberOfLinesPerFile;
Try
{
Using (StreamReader sr = New StreamReader(inputfile))
{
int fileNumber = 0;
While (!sr.EndOfStream)
{
int count = 0;
Using (StreamWriter sw = New StreamWriter(outpath + "_" + ++fileNumber + ".txt"))
{
sw.AutoFlush = True;
While (!sr.EndOfStream && ++count < linesPerFile)
{
sw.WriteLine(sr.ReadLine());
}
}
}
}
}
Catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
vrdabberu
(Varunraj Dabberu)
June 24, 2024, 2:24pm
2
Hi @jennifer.cannon
Try this C# Code:
string inputfile = inputFileName;
string outpath = outputPath;
int linesPerFile = numberOfLinesPerFile;
try
{
using (StreamReader sr = new StreamReader(inputfile))
{
int fileNumber = 0;
while (!sr.EndOfStream)
{
int count = 0;
using (StreamWriter sw = new StreamWriter(outpath + "_" + ++fileNumber + ".txt"))
{
sw.AutoFlush = true;
while (!sr.EndOfStream && ++count <= linesPerFile)
{
sw.WriteLine(sr.ReadLine());
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Invoke Code Arguments:
Variables:
Note: Make sure to keep Language as C#
Regards
vrdabberu
(Varunraj Dabberu)
June 24, 2024, 3:34pm
4
Perfect, so the topic can be closed @jennifer.cannon
Please mark my post as solution to close the loop.
Forum FAQ - How to mark a post as a solution
This document is part of our beginners guide .
This article will teach you how to properly mark a post as a solution.
We were closely following our last UiPath Forum feedback round! topic and carefully extracted all the bits of feedback that was provided. As such, we would like to tackle the topic of solutions on our Forum and how to properly use them.
When is the topic resolved?
The topic can be considered resolved when the topic author has fo…
Regards
system
(system)
Closed
June 27, 2024, 3:34pm
5
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.