I am running c# application in service mode. And i am using pdf2swf tool to convert odf to swf format. Images saved in pdf is converting. But if any test adding to pdf is not getting converted in service mode.
But when run as UI mode(Consoleapplication.exe) then everything is getting converted.
string inputFileName = this.Filename;
string outputFileName = inputFileName.Replace("pdf", "swf");
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0} -o {1}", inputFileName, outputFileName);
string executingDirPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
string dataDirectoryPath = Path.Combine(executingDirPath, "pdf2swf.exe");
ProcessStartInfo psi = new ProcessStartInfo(dataDirectoryPath, sb.ToString());
psi.UseShellExecute = false;
System.Diagnostics.Process pdf2swf = new System.Diagnostics.Process();
pdf2swf.StartInfo = psi;
pdf2swf.Start();
pdf2swf.WaitForExit();
pdf2swf.Close();
pdf2swf.Dispose();
Regards
Sangeetha
Direct using process to start pdf2swf.ext maybe had some privilege problems.I used another way to solve this problem,write a batch file,then running the batch file by process.
Batch file sample:
c:
cd C:\Program Files (x86)\SWFTools\
pdf2swf.exe -f -T 9 -t "%1" -o "%2"
Code in program:
Process p = new Process();
string path = basePath + "/plugin/ConvertToSwf.bat";//batch file path
ProcessStartInfo pi = new ProcessStartInfo(path, filePath + " " + swfPath);//passing the file path and converted file path to batch file
pi.UseShellExecute = false;
pi.RedirectStandardOutput = true;
p.StartInfo = pi;
p.Start();
p.WaitForExit();
I faced a similar problem recently. I solved the issue by adding a separate console application(Consoleapplication.exe) with administrative-rights that runs on my server without shell.
Also, try to upgrade to the newest version of pdf2swf.
FYI. I recently had this problem (thought it was fonts not being embedded but actually was missing all text in converted swf). What fixed it for me was to set:
pi.UseShellExecute = false;
AND set the working directory;
pi.WorkingDirectory = "C:\windows\temp"; // path where read & write is
Related
I am using Doscan.exe of SEP to scan files before uploading but there is no provision provided by SEP to generate a separate log file for each scanned file, so that's why I am not able to make sure whether the file is ok or not for uploading.
If anyone has a way to check this thing then please let me know.
I am using version 14.2
Thanks.
ProcessStartInfo start = new ProcessStartInfo();
start.Arguments = " /ScanFile C:\\Users\\New Text Document (2).txt";
start.FileName = #"C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\14.2.3332.1000.105\Bin\DoScan.exe";
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
}
I can use process start and run a standard vbscript without its .vbs extension (see my code below) but how do you run a vbscript file that has been encoded using the VBScript Encoder object without the .vbe extension?
Process process = new Process();
process.StartInfo.FileName = #"wscript.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = "//e:vbscript noExtensionFile";
process.Start();
If you're trying to run an encoded VBScript file, you want the VBScript.Encode engine rather than the VBScript engine. Try using //e:VBScript.Encode as your first argument to wscript.
Assuming your problem is with the file not having an extension and you can rename it you could do something like:
string filename = ....
if (!Path.HasExtension(filename))
{
string t = Path.ChangeExtension(filename, ".vbe");
File.Move(filename, t);
filename = t;
}
// rest of your code
I have the below code. As per my knowledge it is converting and saving as pdf. Can anyone explain this code?
Process cnp = new Process();
cnp.StartInfo.FileName = "AcroRd64.exe";
cnp.StartInfo.Arguments = "/n /t c:/test.jpg Microsoft Office Document Image Writer";
Updates:
I created a sample console application to trigger print and it is not working
class Program
{
static void Main(string[] args)
{
try
{
Process p = new Process();
p.StartInfo.FileName = #"C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe";
p.StartInfo.Verb = "Print";
p.StartInfo.Arguments = "/n /t c:/test.png " + "Microsoft Office Document Image Writer";
p.StartInfo.CreateNoWindow = false;
p.StartInfo.UseShellExecute = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadKey();
}
}
Process is used to start and stop processes on your system.
Seems pretty clear that your code attempts to start a process "AcroRd64.exe", which I would guess is the pdf-reader Adobe Acrobat Reader. Argumens are arguments to the process, so basically, this is the equivalent of writing the following in command line:
AcroRd64.exe /n /t c:/test.jpg Microsoft Office Document Image Writer
There's a little more info on this under this other SO question.
Your code might doesn't work because the single argument Microsoft Office Document Image Writer contains whitespace. Try:
cnp.StartInfo.Arguments =
"AcroRd64.exe /n /t c:/test.jpg \"Microsoft Office Document Image Writer\"";
I would like to import to registry a .reg file that exist in project resources.
The way to import a reg file uses the path to the reg file:
Process proc = new Process();
proc = Process.Start("regedit.exe", "/s " + "path\to\file.reg");
Is it possible to do so with a file from resources? how do I get its path?
If it is in the project folder. i-e. The folder in which the project is runnung. you can access it directly : Process.Start("regedit.exe", "/s " + "Filename.reg");
you can get the current path by using
string path =System.AppDomain.CurrentDomain.BaseDirectory; // this will give u the path for debug folder
or
string projectPath= Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())); //This will give u the project path.
you can use both and navigate arround to get the path to your desired folder. eg if you want to access a file in the Resource folder inside the project folder u can use projectPath+"\\Resource\\filename.reg"
If the file is embedded resource (and as such is not created on disk), it is best to read it like this and save it to a temporary file using:
var path = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), "reg");
Process.Start(path);
It may not be necessary to change the extension if you don't start the file directly but use Process.Start("regedit", "/s " + path) like you described in your question. Keep in mind that the file path should be escaped so it's parsed properly as the command line argument, temporary file path, though, will not contain spaces, so it should be okay.
This is not tested code, but you get the steps I hope:
Process proc = new Process();
proc.StartInfo.FileName = "regedit.exe";
proc.StartInfo.Arguments = "/s";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.Start();
StreamWriter stdin = myProcess.StandardInput;
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "<regfile>";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
stdin.Write(reader.ReadToEnd());
}
I want to monitor a directory and FTP any files that are place there to an FTP location. does anyone know how to do this in c#?
Thanks
EDIT: Anyone know of a good client that can monitor a directory and FTP and files placed in it?
I combination of the System.IO.FileSystemWatcher and System.Net.FtpWebRequest/FtpWebResponse classes.
We need more information to be more specific.
When used in conjunction with the FileSystemWatcher, this code is a quick and dirty way to upload a file to a server.
public static void Upload(string ftpServer, string directory, string file)
{
//ftp command will be sketchy without this
Environment.CurrentDirectory = directory;
//create a batch file for the ftp command
string commands = "\n\nput " + file + "\nquit\n";
StreamWriter sw = new StreamWriter("f.cmd");
sw.WriteLine(commands);
sw.Close();
//start the ftp command with the generated script file
ProcessStartInfo psi = new ProcessStartInfo("ftp");
psi.Arguments = "-s:f.cmd " + ftpServer;
Process p = new Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
File.Delete(file);
File.Delete("f.cmd");
}