I am having an issue with the Revit API PrintManager properties, in particular with the PrintToFileName property and the error: Invalid fileName.
What is the proper way to declare what you wish for a printed view to be named when printing to pdf?
My Source (Puts a schedule onto an empty sheet and prints it):
ViewSheet sheet = ViewSheet.Create(Doc, ElementId.InvalidElementId);
Element view = new FilteredElementCollector(Doc)
.OfClass(typeof(ViewSchedule))
.Where(o => o.Name == element) //element is a string from a list of items in a WPF listbox.
.First();
ScheduleSheetInstance.Create(Doc, sheet.Id, view.Id, XYZ.Zero);
ViewSet set = new ViewSet();
set.Insert(sheet);
IList<ElementId> print = new List<ElementId>();
print.Add(sheet.Id);
Uidoc.Selection.SetElementIds(print);
printManager.PrintRange = PrintRange.Select;
ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
viewSheetSetting.CurrentViewSheetSet.Views = set;
printManager.SelectNewPrintDriver("Adobe PDF");
printManager.PrintToFile = true;
printManager.CombinedFile = true;
printManager.PrintToFileName = "TestFileName"; //ERROR HERE
printManager.Apply();
printManager.SubmitPrint(sheet);
Update: Found the problem in my formatting thanks to Bogdans post as well as This comment on the Autodesk Revit Api Forum.
Turns out, the PrintToFileName calls for both a path and a filename string. Working snippet is as follows:
string path = @"[same file path here ]";
string currentViewName = view.Name;
printManager.PrintToFileName = path + currentViewName + ".pdf";
printManager.Apply();
Thanks for the response, Bogdan.