I want to print all selected files which are displayed in a Datagrid.
I donĀ“t want to print them one after another, I want all to add them into a print queue because I want to use FinePrint.
FinePrint is a printer driver that can add all documents in the print queue to a single file for printing. In Windows Explorer you can select files and right-click Print on them. When FinePrint is selected as the default printer it opens the FinePrint Window and attaches all the selected Files to one file. Then you can do other stuff like set stamps on the pages.
I want to create the same thing in my WPF project, but it would be enough to just select files and click on a button.
EDIT:
The complete Method:
void btnPrint_Click(object sender, RoutedEventArgs e)
{
List<ZeichnungInDB> selectedItemsList = dataOutOfDb.SelectedItems.Cast<ZeichnungInDB>().ToList();
if(selectedItemsList.Count > 0)
{
PrintDialog printDialog = new PrintDialog();
FileInfo fileInfo;
if (printDialog.ShowDialog() == true)
{
foreach (ZeichnungInDB zeichnung in selectedItemsList)
{
fileInfo = new FileInfo(#"..." + zeichnung.Zeichnungsnummer + "_" + zeichnung.Index + "_VIN_" + zeichnung.Volante_Index + zeichnung.Extension);
using (FileStream file = fileInfo.OpenRead())
{
System.Windows.Markup.ParserContext context = new System.Windows.Markup.ParserContext();
context.BaseUri = new Uri(fileInfo.FullName, UriKind.Absolute);
object doc = (System.Windows.Markup.XamlReader.Load(file, context));
DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator;
printDialog.PrintDocument(paginator, "Printing from MMS");
}
}
}
}
}
It throws a XamlParseException where I create the doc object, directly at the beginning of the File.
Basically you set a registry key (counter) and then print them the normal way (one after another) FinePrint decrements the counter and adds them to one job.
From: http://fineprint.com/fpsupport-topic/fineprint-developer-kit/
Using the CollectJobs registry setting, FinePrint will collect
multiple print jobs before printing them.
The DWORD registry key is:
HKEY_CURRENT_USER/Software/FinePrint
Software/FinePrint8/FinePrinters/FinePrint/CollectJobs
Set the CollectJobs value to the number of print jobs you want to
combine. Each time FinePrint receives a print job, it decrements the
counter. The counter value should be checked to ensure that it has
been decremented before the next job is sent. When all the jobs have
been collected and sent to the output device, the counter is set to
zero.
Related
So I made code again about saving files (you can select file name)
here:
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (Stream s = File.Open(saveFileDialog1.FileName, FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(s))
{
sw.Write(fastColoredTextBox1.Text);
}
}
}
the problem is I want to have 2 selectable extensions:
-.txt
-.md
because the code I wrote can save to any type of file(and if you didn't put anything I will save as . FILE) and I just want only 1 save file type.
Save dialog
You need to set the dialog's Filter property according to the pattern:
Text to show|Filter to apply|Text to show 2|Filter to apply 2|...
For example in your case, where you seem to be saying you want the save dialog to have a combo dropdown containing two things, one being Text and the other being Markdown, your Filter has 4 things:
.Filter = "Text files|*.txt|Markdown files|*.md";
It is typical to put the filter you will apply into the text you will show too, so the user can see what you mean by e.g. "Text files" but I've left that out for clarity.
For example you might choose to make it say Text files(*.txt)|*.txt - the text in the parentheses has no bearing on the way the filter works, it's literally just shown to the user, but it tells them "files with a .txt extension"
Footnote, you may have to add some code that detects the extension from the FileName if you're saving different content per what the user chose e.g.:
var t = Path.GetExtension(saveFileDialog.FileName);
if(t.Equals(".md", StringComparison.OrdinalIgnoreCase))
//save markdown
else
//save txt
You can just use the filter of your dialog to set the allowed extensions:
// Filter by allowed extensions
saveFileDialog1.Filter = "Allowed extensions|*.txt;*.md";
When i select a folder manually, through FolderBrowserDialog, my need to substitute the path to the code below.
Where "%ProgramFiles (x86)%\MyApp" must be replaced with the variable of the selected folder + file name.
As a result, when selecting a folder, the file size "testFile.txt" in "label1" should be displayed (there will be two or more such files).
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
DialogResult result = folderBrowser.ShowDialog();
if (result == DialogResult.OK)
{
// Determine the size of the file in KB (dividing the number of bytes by 1024)
FileInfo fs1 = new FileInfo(Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%\\MyApp\\testFile.txt"));
long FileSize1 = fs1.Length / 1024;
label1.Text = "testFile.txt (" + Convert.ToString(FileSize1) + " KB)";
if (FileSize1 > 180 & FileSize1 < 186) // If the file is larger and smaller than the specified sizes
{
label1.ForeColor = Color.Green;
}
else
{
label1.ForeColor = Color.Red;
}
}
}
Decision, edit:
FileInfo fs1 = new FileInfo(folderBrowser.SelectedPath + "\\testFile.txt");
or
FileInfo fs1 = new FileInfo(Path.Combine(folderBrowser.SelectedPath, "testFile.txt"));
The official documentation has an item dedicated specifically to this: How to: Choose Folders with the Windows Forms FolderBrowserDialog Component
To choose folders with the FolderBrowserDialog component
In a procedure, check the FolderBrowserDialog component's DialogResult property to see how the dialog box was closed and get the
value of the FolderBrowserDialog component's SelectedPath property.
If you need to set the top-most folder that will appear within the tree view of the dialog box, set the RootFolder property, which takes
a member of the Environment.SpecialFolder enumeration.
Additionally, you can set the Description property, which specifies the text string that appears at the top of the
folder-browser tree view.
In the example below, the FolderBrowserDialog component is used to
select a folder, similar to when you create a project in Visual Studio
and are prompted to select a folder to save it in. In this example,
the folder name is then displayed in a TextBox control on the form. It
is a good idea to place the location in an editable area, such as a
TextBox control, so that users may edit their selection in case of
error or other issues. This example assumes a form with a
FolderBrowserDialog component and a TextBox control.
public void ChooseFolder()
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
}
According to that example, you can get a string to the chosen folder using folderBrowser.SelectedPath.
I have been making a form to let the user save his progress. There are 6 virtual slots which contain different save files read from a folder. I want to have the same set up just with a scrollbar to let user scroll through save files, in case he has more than 6 made.
The set up is: picturebox which loads save file when clicked, label for file name and for file date, picturebox to delete the save file, and a panel underneath to save file when the slot is clicked.
Below is the code I use to load in 6 save files. (I will get the date by reading the save file start as it contains the date, but I have not done that part yet).
private void loadsavestoscreen()
{
string filename;
string extension;
string locpath = #"C:\test";
String[] allfiles = System.IO.Directory.GetFiles(locpath, "*.*", System.IO.SearchOption.TopDirectoryOnly);
int counter = 0;
foreach (String file in allfiles)
{
if (counter == 6 || counter == allfiles.Length - 1)
{ labelcheck(); break; }
if ((extension = Path.GetExtension(file)) == ".dat")
{
filename = Path.GetFileNameWithoutExtension(file);
//Console.WriteLine(filename);
changelbl(counter, filename);
counter++;
}
}
}
'labelcheck' checks if the text is correct, if not it hides the label.
'lblchange' changes the name of the label on the correct slot.
My question is: How would I implement a scrollbar to allow the user to scroll through more save files when there is more than 6?
Here's a snippet of the form:
I am slightly new to programming so my apologies if I've made some obvious errors. Thanks for any help.
Without a list object or a container this is not very easy to solve.
I suggest you to use a DataGridView or a ListView object. You can easily add your file entries as objects to these lists. They have an option Scrollable, which you can set true or false.
I would also create a class for that save file entries (storing label/image position and contents) and add them to your DataGridView or ListView.
If you want to know how to add images to those controls:
How do add image to System.Windows.Forms.ListBox?
I'am pretty new to C# and I want a listbox with all text files in a folder and if the user dubbleclicks on the listed file the file will display in a textbox.
I don't want to use the openFileDialog function because the textfiles are on a webserver which I access using username:password#server.com/folder.
Kinda like a texteditor limited to edit only files in 1 folder :)
If this is possible using openFileDialog please tell me how.
I hope you can understand what I want to do.
Greetings,
From what I understand you are after, you want to iterate through the files in a specific directory and then allow them to be edited once opened with a double click in a listbox.
This can be done using the var Files = Directory.GetFiles("path", ".txt");
Files would be a string[] of the file names.
Then filling the Listbox with the files something like this:
ListBox lbx = new ListBox();
lbx.Size = new System.Drawing.Size(X,Y); //Set to desired Size.
lbx.Location = new System.Drawing.Point(X,Y); //Set to desired Location.
this.Controls.Add(listBox1); //Add to the window control list.
lbx.DoubleClick += OpenFileandBeginEditingDelegate;
lbx.BeginUpdate();
for(int i = 0; i < numfiles; i++)
lbx.Items.Add(Files[i]);
lbx.EndUpdate();
Now your event delegate should look something like this:
OpenFileandBeginEditingDelegate(object sender, EventArgs e)
{
string file = lbx.SelectedItem.ToString();
FileStream fs = new FileStream(Path + file, FileMode.Open);
//Now add this to the textbox
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
tbx.Text += temp.GetString(b);//tbx being the textbox you want to use as the editor.
}
}
Now to add an event handler through the VS window editor click on the control in question and go to the properties pane for that control. You will need to then switch to the events pane and scroll untill you find the DoubleClick event if you use that the designer should auto-insert a valid delegate signature and allow you to write the logic for the event.
Has anyone worked with setting the InSession.Views property?
The problem I have is that when I set the following property immediately after opening a document it doesn't work (i.e. the Views size is still 0 even though the viewSet has 4 items).
revitDocument.PrintManager.ViewSheetSetting.InSession.Views = viewSet;
but after modifying the In-Session view/sheet set using print dialog in revit, then I can assign to it.
does anyone know why?
Revit stores the current view sheet set in the variable Document.PrintManager.ViewSheetSetting.CurrentViewSheetSet and that's what it's really using . At the beginning when you are setting the InSession you should be setting the CurrentViewSheetSet instead. The reason that it is working after using the print dialog is that it is setting the CurrentViewSheetSet to InSession. What I would do is to create a temporary ViewSheetSetting on document open and then delete it when the document closes. Below is some of the code that I used though with mine I only kept the ViewSheetSetting for the scope of a single function call instead of from document open to document close.
For Open
const string tempoarySheetSetSettingName = "Temp Sheet Set";
ViewSheetSetting viewSheetSetting = _printManager.ViewSheetSetting;
//Save your temporary sheet set
_printManager.ViewSheetSetting.SaveAs(tempoarySheetSetSettingName);
ViewSheetSet selected = null;
FilteredElementCollector viewCollector = new FilteredElementCollector(document);
viewCollector.OfClass(typeof(ViewSheetSet));
//Find the sheet set that you just created
foreach (ViewSheetSet set in viewCollector.ToElements())
{
if (String.Compare(set.Name, tempoarySheetSetSettingName) == 0)
{
selected = set;
break;
}
}
//Set the current view sheet set to the one that you just created
viewSheetSetting.CurrentViewSheetSet = selected;
//Set the views to which ever set you would like to print
viewSheetSetting.CurrentViewSheetSet.Views = viewSetToPrint;
viewSheetSetting.Save();
For Printing
Your user will need to select the temporary view set that you created whenever they print.
For Close
_printManager.ViewSheetSetting.Delete();
In Revit 2015 using VB.Net I couldn't force this ViewSheetSet Colletor to work like this:
Dim VSSCollector As New FilteredElementCollector(curDoc)
VSSCollector.OfClass(oftype(ViewSheetSet))
Instead I used this and it worked:
Dim VSSCollector As New FilteredElementCollector(curDoc)
VSSCollector.OfClass(GetType(ViewSheetSet))