What would be powershell version of this c# code? I am having hard time get this work in Powershell especially stringbuilder and files.add line where utf8encoding is. Here is my powershell version of the code. http://wikisend.com/download/429800/Add_Files_PS.txt. Here is the error.
Missing expression after ','. At C:\PowerShell\Add_Item.ps1:60 char:73 + $newFile = $docLibrary.RootFolder.Files.Add($newDestinationFolderPath, <<<< UTF8Encoding.UTF8.GetBytes(builder.ToString()), $true) + CategoryInfo : ParserError: (,:String) [], ParseException + FullyQualifiedErrorId : MissingExpressionAfterToken
using ( SPSite siteCollection = new SPSite( "http://moss.litwareinc.com" ) ) {
using ( SPWeb web = siteCollection.OpenWeb( "docs" ) ) {
SPList list = web.Lists["Sample"];
//link to the file
string fileLinkUrl = "http://moss.litwareinc.com/docs/Shared%20Documents/ConfigureIRMinWSS30.doc";
StringBuilder builder = new StringBuilder();
using ( TextReader reader = new StreamReader( @"C:\linktodocumenttemplate.txt" ) ) {
builder.Append( reader.ReadToEnd() );
}
//replace string template with values
builder.Replace( "{0}", fileLinkUrl );
//should change the name of the .aspx file per item
SPFile file = list.RootFolder.Files.Add( "link_title.aspx", UTF8Encoding.UTF8.GetBytes(builder.ToString()));
//set list item properties
SPListItem item = file.Item;
item["Content Type"] = "Link to a Document";
SPFieldUrlValue itemUrl = new SPFieldUrlValue();
itemUrl.Description = "From sample code";
itemUrl.Url = fileLinkUrl;
item["URL"] = itemUrl;
//persist changes
item.Update();
}
}