I'm coding a Wpf application to print docx files. I can normally print it. This my code:
var info = new Process();
info.StartInfo = new ProcessStartInfo(filePath) //in this pass the file path
{
UseShellExecute = true
};
info.StartInfo.Verb = "Print";
info.StartInfo.CreateNoWindow = true;
info.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
info.Start();
info.WaitForExit();
info.Dispose();
But now, I want to print pages in this docx file by reverse order. First I wonder how can I use AddCoreProperty in DOCX package, but i don't find anyway to use it to print reverse order. I searched but could find any helpful information. Maybe by another solution, all useful with me.
Related
So until now I was testing the application using a local path to find the file that I try to work with
string path = #"A:\Log\OLP_Application_Storage\call.bat";
try
{
Process process = new Process();
process.StartInfo.FileName = "call.bat";
process.StartInfo.WorkingDirectory = #"A:\Log\OLP_Application_Storage\call.bat";
process.StartInfo.Arguments = "call.bat";
process.Start();
}
I have a bat file that calls a python script, with this path is working like a charm. The thing is that I try my app to be used by multiple users (the ones that have acces to my onedrive) so I need to use the share link from onedrive, I dont know how to addapt it, only replacing the path with the link it does not work.
string path = https://companyname-my.sharepoint.com/:x:/p/userid/ewaaiwjfafjwiajawfiaf";
try
{
//string pth;
//pth = "A:\Log\OLP_Application_Storage\call.bat";
Process process = new Process();
process.StartInfo.FileName = "call.bat";
process.StartInfo.WorkingDirectory = "https://companyname-my.sharepoint.com/:x:/p/userid/ewaaiwjfafjwiajawfiaf";
process.StartInfo.Arguments = "call.bat";
process.Start();
}
I tried something like this but is not working.
Thank you for your time!
Edit: I am not very good at exprimation so it may be confusing.
I use a txt file as a list of ids of users, I use an excel file to store some data when a user uses the app, he insert in couple of spaces, he press send and the app saves it inside excel file. I did all the code on local, but now I want to share the app inside the company. To be able to write mutiple users at the same time inside the excel file, it has to be inside Onedrive. So now I have to find out how to get to it for me to use it (The difference should be seen in the 2 codes example). Thank again for the wasted time! It may be a easy problem but I am new to the app production world...
I'm beginner developer. I'm building a windows desktop form application like a notepad. The user will fill contact info and add text when the information is loaded, the user should be able to save the form as .pdf file and the possibility to print out the entire form directly, same as it was loaded. Which the best and quick alternative to accomplish this on c#?
Save a .pdf file at least on C#
You can use an installed PDF Reader by this:
Process prcs = new Process();
prcs.StartInfo = new ProcessStartInfo()
{
CreateNoWindow = true,
Verb = "print",
FileName = #"your file path"
};
prcs.Start();
I am writing an app which performs some tests and produces a number of different reports. These may be any combination of Labels, PDF for end customer, PDF for repair department, XML file etc.
Depending on the report type, I need to send the file to either the file system or to one of a number of different printers (A4, label etc). Ideally there should be no popup windows - just straight to paper.
How can I send a file (PDF, XML) to a printer? I had thought that for XML/Text I could just File.Copy to LPTn but that doesn't seem to work. For PDF I'm guessing that I could call Acrobat with some parameters which cause the PDF to be printed.
The printers I use are mapped to LPTn. Is there a better way to do this and to store the definitions in the app? i.e. Labels go to MyLabelPrinter and A4 PDFs got to MyA4Printer.
Has anyone done this?
ProcessStartInfo info = new ProcessStartInfo("[path to your file]");
info.Verb = "PrintTo";
info.Arguments = "\"[printer name]\"";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
Take a look at this webpage. You should find the info you are looking at for PDF.
For example, it will look like that:
ProcessStartInfo infoOnProcess = new ProcessStartInfo("C:/example.pdf");
info.Verb = "PrintTo";
//Put a if there, if you want to change printer depending to file extension
info.Arguments = "\"HP-example-Printer\"";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(infoOnProcess);
I want to zip a file using PZKip in C# .net. I am using VS 2008. Can any one of you please help me with a C# .net code example.
When you say PKZip, does that mean you actually have the executable and you want to use that to ZIP a file? If that's the case, you can call the EXE through C# rather easily:
ProcessStartInfo startInfo = new ProcessStartInfo("pkzip.exe", "output.zip /add file1.txt file2.jpg file3.png");
startInfo.CreateNoWindow = true; // Let's not show the DOS box
// Execute the process
Process zipProcess = Process.Start(startInfo);
zipProcess.WaitForExit();
I don't know what the parameters, specifically, are for pkzip, but you can probably figure that out quite easily.
Now, if on the other hand you're asking about how to compress a file programmatically in C# to ZIP format, I would recommend you grab SharpZipLib. It supports several formats, including Zip, Gzip, BZip2, and Tar. It comes with sample code and it's open source.
You can grab it here: http://www.icsharpcode.net/opensource/sharpziplib/
Just in case you don't want to use PKZIP anymore and you don't want to use sharpziplib, .NET has built in compression classes:
http://msdn.microsoft.com/en-us/library/system.io.compression.aspx
If you must use PKZip then try this basic example:
static void Main(string[] args)
{
var p = new Process();
p.StartInfo.FileName = #"Path to pkzip.exe";
p.StartInfo.Arguments = "the args";
p.Start();
}
I have one button and one textbox on form. When I click on the button, Microsoft Word is started. When the user closes Word, I want to get the file name that the user saved his work under to show up in the text box.
I am using the following code for button_click:
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(#"C:\Program Files\Microsoft Office\Office12\winword.exe");
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput = listFiles.StandardOutput;
listFiles.WaitForExit();
if (listFiles.HasExited)
{
System.IO.FileInfo ff = new System.IO.FileInfo(myOutput.ToString());
string output = myOutput.ReadToEnd();
this.processResults.Text = output;
}
I don't believe this is possible via the command line. Also, realize that, if the user opens another document, your code will not finish, since it'll wait until all of the docs are closed (the process won't end until that point).
That being said, you should be able to use the Word/Office Interop libraries, and listen to the DocumentBeforeSave and/or DocumentBeforeClose events. This should let you pull the information from the Document itself, right as it's being saved/closed.
I don't think you can do this with the current code you have. ProcessStartInfo is very generic and has no knowledge of word.
I think you will want to use Visual Studio Tools for Office (VSTO) to start word. This way you have a reference to the word application and document and can get the document name.
this article should get you started http://www.c-sharpcorner.com/UploadFile/mgold/WordFromDotNet11082005235506PM/WordFromDotNet.aspx the sample code has a object called aDoc. Then after the save you can check aDoc.FullName to get the path.
I'm not sure whether it's possible or not because name of the saved file is an internal information that's not public for other applications.
Instead in your particular case since you are using MS Word you can use Word interop to start the Word application in your application and then handle its events
Create a blank Word document in the desired location, and then get Word to load that?