I have the path to a Word document saved in an SQL Database.
I am able to retrieve the path but I cannot work out the best approach to open the Word document from WPF without using the OpenFileDialog. I've given up any thoughts of embedding Word in WPF as it has too many gotchas.
I just want to be able to click a button or hyperlink and using the retrieved document path, open Word.
Try something like
Process wordProcess = new Process();
wordProcess.StartInfo.FileName = pathToYourDocument;
wordProcess.StartInfo.UseShellExecute = true;
wordProcess.Start();
By setting UseShellExecute to true it will open the document using the default program,
in your case Word.
Related
I have embedded a WebBrowser control in my application and display content that I receive from a server. Specifically: The control is bound to a string which contains the error message from a rest call, that sometimes is HTML.
I wonder if there is a security risk if active content, e.g. JavaScript would be sent as part of the error message. Is there a way to instruct the WebBrowser control to disable all active content?
There are several ways to do:
First way is remove javascript from your string before pass it to browser, from Elian Ebbing's answer:
The quick 'n' dirty method would be a regex like this:
var regex = new Regex(
"(\\<script(.+?)\\</script\\>)|(\\<style(.+?)\\</style\\>)",
RegexOptions.Singleline | RegexOptions.IgnoreCase
);
string ouput = regex.Replace(input, "");
The better* (but possibly slower) option would be to use
HtmlAgilityPack:
HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(htmlInput);
var nodes = doc.DocumentNode.SelectNodes("//script|//style");
foreach (var node in nodes) node.ParentNode.RemoveChild(node);
string htmlOutput = doc.DocumentNode.OuterHtml;
*) For a discussion about why it's better, see this thread.
That way seem better and easier.
Second way is use WinForms webbrowser control, which allow you control lower level of browser, but this involve some invoking to WinAPI.
You can see this link for more info.
I have spent several hours researching this and can't seem to locate the answer.
I have downloaded and referenced itextsharp in my wpf .net application. (VB)
What I am doing is needing to turn off a specific layer (ocg object) in an exisiting .pdf that was created in Autocad that is defaulted on.
I have successfully opened and displayed the .pdf but i can't seem to use the setOCGstate control correctly
pdf name is "random.pdf"
layer name that i can see once i open the .pdf is "Option 1"
where im getting stuck is i know the layer names are stored in an array inside the .pdf. i know the name of the layer i am trying to turn off, so how do i reference that layer and turn it off using the setocgstate.
example code
dim doc1 as New PdfReader("random.pdf")
PdfAction.SetOCGstate ("confused", False)
I've created an example that turns off the visibility of a specific layer. See ChangeOCG
The concept is really simple. You already have a PdfReader object and you want to apply a change to a file. As documented, you create a PdfStamper object. As you want to change an OCG layer, you use the getPdfLayers() method and you select the layer you want to change by name. (In my example, the layer I want to turn off is named "Nested layer 1"). You use the setOn() method to change its status, and you're done:
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
Map<String, PdfLayer> layers = stamper.getPdfLayers();
PdfLayer layer = layers.get("Nested layer 1");
layer.setOn(false);
stamper.close();
reader.close();
This is Java code. Please read it as if it were pseudo-code and adapt it to your language of choice.
I saw this code ealier about drag and dropping attachment files (http://www.codeproject.com/Articles/28209/Outlook-Drag-and-Drop-in-C) from Outlook into Windows Form and it works fine in windows Forms, but I can't seem to make it work with WPF.
I tried to simply change System.windows.form.IDataObject to System.Windows.IDataObject but it doesn't work (as I should have guessed).
I also simply tried to get the content of the e.Data FileContents but always get errors (which seems to be the case to everyone when I check on the web).
Did anyone ever did drag and dropping attachment from Outlook to WPF ? I am at a complete loss.
Edit : I am not trying to get file from a Windows Explorer windows ( I do but I know how to). It's really the whole getting attachment from Outlook directly that doesn't work . I am fully aware too that I could simple take the file from outlook into a temp folder and then drop it into my program, but I would like to avoid this unncessary step if possible.
so in the end I was able to find out a link where someone did exactly that :
https://gist.github.com/MattyBoy4444/521547
For those who wonders. Here is what I did exactly.
Create a new project in C# (my code is in VB) and add the code to it
Reference the new project in my main project to be able to use it
In my drop Event, check whether or not I had the "FileGroupDescriptorW" object in the drop data and called the method if I do to retrieve the files.
Here is the complete code
If obj.GetDataPresent("FileGroupDescriptorW") Then 'Outlook
Dim oOutLookObj As New Helpers.OutlookDataObject(e.Data)
Dim StrFiles() As String = oOutLookObj.GetData("FileGroupDescriptorW")
Dim contentStream() As System.IO.MemoryStream = oOutLookObj.GetData("FileContents")
' Do intended work...
End if
The names of the files are in StrFiles and the content are found in the streams. Both have the same array size and are order correctly.
I want to build a context sensitive help for a winforms application, to do this I use a class with a reference to the HelperProvider component, HelpNamespace is set to the index html file and when a form is loaded I register each control in the form to the helperprovider with a topic that I get from a config file :
helpProvider.SetShowHelp(control, true);
helpProvider.SetHelpNavigator(control, helpNavigator);
helpProvider.SetHelpKeyword(control, helpKeyword);
when debugging I am sure that some controls are configured with some topics different from index file but when running and pressing F1 its always the index file (HelpNamespace) that is opened. When using a HelperProvider instance for each control and no single instance for all controls, that works fine!
Why I can't use a single instance of helperProvider for all controls?
You need SetHelpKeyword for each control. A HelpNavigator.TopicId may be useful for a CHM with topic ID's inside.
I'm missing ".Topic" in your code sample above. Try the code below or download a working example from:
http://www.help-info.de/files_download/CSharp2008_CHM.zip
// set F1 help topic for controls on this form
helpProvider1.SetHelpNavigator(this.btnStart, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.btnStart, #"/Garden/flowers.htm");
helpProvider1.SetHelpNavigator(this.btnExit, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.btnExit, #"/Garden/tree.htm");
helpProvider1.SetHelpNavigator(this.chkShowHelpWithNavigationPane, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.chkShowHelpWithNavigationPane, #"/HTMLHelp_Examples/jump_to_anchor.htm#AnchorSample");
I am trying to figure out how to make a hyperlink in a Livecycle Form which points to a URL which will change on different days that the form is rendered. For example on one day I might want the hyperlink to point to:
mywebsite/mypage?option=XXX
and on another day I want it to point to:
mywebsite/mypage?option=YYY
The XXX and YYY can be passed into the form's data pretty easily as XML, but I just don't know how to make it so that the hyperlink is changed to correspond to this.
Any suggestions?
This can be accomplished with JavaScript in LiveCycle Designer. The following script, placed on the Form's docReady event will let you dynamically change the URL of a text object.
form1::docReady - (JavaScript, client)
// If this code is running on the server, you don't want it to run any code
// that might force a relayout, or you could get stuck in an infinite loop
if (xfa.host.name != "XFAPresentationAgent") {
// You would load the URL that you want into this variable, based on
// whatever XML data is being passed into your form
var sURL = "www.stackoverflow.com"; // mywebsite/mypage?option=xxx
// URLs are encoded in XHTML. In order to change the URL, you need
// to create the right XHTML string and push it into the Text object's
// <value> node. This is a super simple XHTML shell for this purpose.
// You could add all sorts of markup to make your hyperlink look pretty
var sRichText = "<body><p>Foo</p></body>";
// Assuming you have a text object called "Text1" on the form, this
// call will push the rich text into the node. Note that this call
// will force a re-layout of the form
this.resolveNode("Text1").value.exData.loadXML(sRichText, false, true);
}
There are a couple of caveats: URLs in Acrobat are only supported in Acrobat 9.0 and later. So if someone using an older version of Acrobat opens your form, the URLs won't work.
Also, as you can see from the "if (xfa.host.name !=...)" line, this code won't run properly if the form is being generated on the server, because forcing a re-layout of a form during docReady can cause problems on certain older versions of the LiveCycle server. If you do need to run this script on the server, you should probably pick a different event then form::docReady.
I a number of complaints from users in WorkSpace that clicking links opened them in the same tab so they lost their WorkSpace form, and there's no option to change that in Designer 11. I think the solution I came up with for that would work for you too.
I made buttons with no border and no background, and in their click event have this line (in Javascript, run at client)
app.launchURL("http:/stackoverflow.com/", true);
It would be easy to add some logic to choose the right URL based on the day and it doesn't cause any form re-rendering.
In some spots where the hyperlink is in line with other text, I leave the text of the link blue and underlined but with no hyperlink, and just place the button (no background, no border, no caption) over it. Does require positioned and not flowed subforms for that to work, so depending on your layout it could get a little clunky.
Wow, just realized I am super late to the party. Well, for anyone using ES4 facing a similar problem . . .
Ended up using a 3rd party component to manipulate the PDF's hyperlinks...wish there was a better solution as this one costs about $1000.