@Rakshitha H P, please try the following steps to generate a word file by using exe in task scheduler.
First, please install Nuget-package DocumentFormat.OpenXml and use the following code.
static void Main(string[] args)
{
string filePath = @"C:\document.docx";
using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(filePath, DocumentFormat.OpenXml.WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = wordDoc.AddMainDocumentPart();
mainPart.Document = new Document();
Body body = new Body();
mainPart.Document.Append(body);
Paragraph titleParagraph = new Paragraph();
Run titleRun = new Run();
titleRun.Append(new Text("This is Title"));
titleParagraph.Append(titleRun);
body.Append(titleParagraph);
Paragraph bodyParagraph = new Paragraph();
Run bodyRun = new Run();
bodyRun.Append(new Text("This is Content"));
bodyParagraph.Append(bodyRun);
body.Append(bodyParagraph);
}
Console.WriteLine("Word doc has been generated");
}
Second, please set the following option to set user account information:(please note that your current user account needs to set administrator power)
Third, please set the exe path in the action:
When you run the task in the task scheduler, the word file will be generated.
Hope my advice could help you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.