Run c# program In Jenkins, cannot save Excel files

Usually get this error:

System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Excel cannot open or save any more documents

After SaveAs method

 

to solve this problem do this works:

  1. Create directory “C:\Windows\SysWOW64\config\systemprofile\Desktop ” (for 64 bit Windows) or “C:\Windows\System32\config\systemprofile\Desktop ” (for 32 bit Windows)
  2. Set Full control permissions for directory Desktop (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user
    “IIS AppPool\DefaultAppPool”

 

See here foe more details:

 

insert a line into a text file after a specific line

from

https://community.spiceworks.com/scripts/show/1709-add-a-line-of-text-into-a-file

briefly:

set objWS = CreateObject("Wscript.Shell")
Set fsob=CreateObject("Scripting.FileSystemObject")

strNewLine = "INSERT LINE TO ADD"
strFileName = "INSERT THE FILE PATH HERE" ' for example c:\textfile.txt

Const FOR_READING = 1
Const FOR_WRITING = 2
strCheckForString = UCase("NEW LINE WILL BE INSERTED AFTER THIS TEXT")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strFileName, FOR_READING)
strContents = objTS.ReadAll
objTS.Close
arrLines = Split(strContents, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, FOR_WRITING)
For Each strLine In arrLines
  If (Left(UCase(LTrim(strLine)),Len(strCheckForString)) = strCheckForString) Then
    objTS.WriteLine strLine
    objTS.WriteLine strNewLine
  else
    objTS.WriteLine strLine
  End If
Next