I want to read and write/add an alternate data stream(a.k.a Custom Attributes) of a file using C# which has Key-Value pair. - PowerShell commands "set-content" & "get-content"

Hiras, Amit 1 Reputation point
2022-08-09T11:00:26.433+00:00

I want to read and write/add an alternate data stream(a.k.a Custom Attributes) of a file using C# which has Key-Value pair.

If I set "FileTag" using powershell command, I want to read the value of that "FileTag" in my C# code which I can see using "get-content" powershell command.

set-content '\AZ66ST9001.COM\vol2_Stealthbitstest\00-transfer\adsTagTest.txt' -stream "FileTag" -Value "TagValue"

get-content '\AZ66ST9001.COM\vol2_Stealthbitstest\00-transfer\adsTagTest.txt' -stream "FileTag"

Basically, I need a C# code using which I can perform the above 2 PowerShell commands "set-content" & "get-content".

Appriciate your quick help.

Windows for business | Windows Server | Storage high availability | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Hiras, Amit 1 Reputation point
    2022-08-09T12:03:20.54+00:00

    Got the answer with some trial and error.. following is the solution.

    File.WriteAllText(@"\AZ66ST9001.COM\vol2_Stealthbitstest\00-transfer\adsTagTest2.txt:FileTag", "adsTestAmit2");

    var attr = File.ReadAllText(@"\AZ66ST9001.COM\vol2_Stealthbitstest\00-transfer\adsTagTest2.txt:FileTag");

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.