How to set the file name of a Word document without saving it from c# and automation II - ms-word

I have asked here a question on how setting the filename of a Word document via automation without saving it. Thanks to Remou, I have received a nice way doing this via calling the FileSummaryInfo-Dialog and setting the Title-property.
However now I have the problem that the client wants to have document names with special chars in (point and underscore) and it seems to be a bug (or a feature) of word, that it cuts the title and only takes the chars before the first special char for building the file name! I have already googled a lot, however was not able to find a resolution for this problem.
The problem is also noticed here (see under gotcha), however without a solution.
Has anybody another solution for setting the filename without saving, or a workaround/bugfix for the mentioned odd behavior?

Try easyhook, since do not have Windows machine besides my hand these days.
following is just the call flow (something like what i did years ago, changed a software's socket bind port to different one by Detours)
About Hook the CreateFileW:
The example in the easyhook's wiki is just what we want here.
CreateFileHook = LocalHook.Create(
LocalHook.GetProcAddress("kernel32.dll", "CreateFileW"),
new DCreateFile(CreateFile_Hooked),
this);
In the CreateFile_Hooked you can change the parameter InFileName, then call real CreateFileW
static IntPtr CreateFile_Hooked(
String InFileName,
UInt32 InDesiredAccess,
UInt32 InShareMode,
IntPtr InSecurityAttributes,
UInt32 InCreationDisposition,
UInt32 InFlagsAndAttributes,
IntPtr InTemplateFile)
{
// FIGURE OUT THE FILE NAME THAT YOU WANT HERE
// IF the InFileName is not your Document name "My.doc", then call orignal CreateFile
// with all the parameter unchanged.
// call original API...
return CreateFile(
YOUR_CHANGED_FILE_NAME_HERE,
InDesiredAccess,
InShareMode,
InSecurityAttributes,
InCreationDisposition,
InFlagsAndAttributes,
InTemplateFile);
}
Call flow:
After you changed the title to "My_Document_2012_11_29",
then hook the CreateFileW of Word process.
For example when the InFileName is "My.doc",
then you should change it to "My_Document_2012_11_29".
Because this is done in the Word process, so the Detoured function do not know
"My.doc" is mapping to "My_Document_2012_11_29".
There is lot ways to get this mapping info, one is save this mapping info to
a known file in your app, and read the file in the Detoured function.

Related

Automatically download emails from Outlook with SAS or Outlook rule

I am trying to create a program to automatically download the attached files that are sent to us from a certain email and then transform the delimiter with SAS, of those csv that are attached to us and pass those csv through a flow that I have already created.
I have managed to create a program that treats the csv as I want and the delimiter that I want, the problem is that when it comes to automating the download of files from Outlook it does not work.
What I have done is create a rule with the following VB code that I found on the internet:
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\ES010246\Desktop"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
I have changed the path to my personal path where i want the files are downloaded.
website: https://es.extendoffice.com/documents/outlook/3747-outlook
The problem is that this code does not work for me, it does absolutely nothing for me and no matter how much I search the internet, only this code appears.
Is there any other way to do with SAS what I want? What is it to automatically download 8 csv files sent to me by Outlook, or has someone experienced the same thing as me with VBA?
I have followed all the steps about 7 times so I think the error is not in copying the code or selecting certain options wrong, in fact I had copied and pasted the code and later I modified the path where I wanted those to be saved. files but it doesn't work, does anyone know why?
I will be tremendously grateful, thank you very much for everything!
First of all, you need to make sure the file name and path doesn't include forbidden symbols.
The VBA macro used for a rule in Outlook is absolutely valid except that a mail item may contain the attached files with the same name, so a file saved to the disk may be overwritten (saved with the same name). That's why I'd suggest generating a file name with your own unique IDs making sure that DisplayName property is not empty and has a valid name what can be used for file names (exclude forbidden symbols).
Also you may consider handling the NewMailEx event of the Application class which is fired when a new message arrives in the Inbox and before client rule processing occurs. Use the Entry ID returned in the EntryIDCollection string to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem.
The Items.ItemAdd event can be helpful when items are moved to a folder (from Inbox). This event does not run when a large number of items are added to the folder at once.

Reading an SB-Messaging Send Port properties using the Microsoft.BizTalk.ExplorerOM makes a breaking change

I am working on a PowerShell script making use of the Microsoft.BizTalk.ExplorerOM to dynamically update the SB-Messaging SAS key for BizTalk Receive Locations and Send Ports. This is to enable us to roll the SAS keys for our Service Bus queues, and update BizTalk with the new keys as painlessly as possible.
I have this working correctly for Receive Locations, but Send Ports are giving me a different issue.
As soon as I read the PrimaryTransport properties of the Send Port, it seems that some change is made under the covers, that then prevents SaveChanges from working, instead throwing an "Invalid or malformed XML data exception".
This is compared to the the ReceiveLocation, where I can read any of its properties, and then SaveChanges successfully.
Note that in both of this cases, no changes have been made by me. I am simply doing a Read, and then a Save.
Can anyone offer any advice as to what could be causing the issue, and any possible solutions to try?
Had this very same issue, when using Powershell to replace values in ServiceBus ReceiveLocations & SendPorts.
The problem is with the none valid xml symbols in the TransportTypeData, which are converted when the script reads them out in the PS cmd.
All none valid xml symbols (such as the one occuring for Namespace value, ) need to be converted to amp, and if I'm not mistaken even double amp:ed.
Here's an example article showing examples on what I mean by "double amp:ed":
How do I escape ampersands in XML so they are rendered as entities in HTML?
Hope this make sense, and if not, then let me know and I'll give it another go.
Just tried doing this from C#, seems to work ok:
var root = new Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer() { ConnectionString = "Data Source=(local);Initial Catalog=BizTalkMgmtDb;Integrated Security=SSPI;" };
var sendPort = root.SendPorts["xxxx.ServiceBusQueue"];
System.Diagnostics.Trace.TraceInformation(sendPort.PrimaryTransport.TransportTypeData);
sendPort .PrimaryTransport.TransportTypeData = sendPort.PrimaryTransport.TransportTypeData.Replace("RootManageSharedAccessKey", "MySharedAccessKey");
root.SaveChanges();

Why would LayoutObjectNames return an empty string in FileMaker 14?

I'm seeing some very strange behavior with FileMaker 14. I'm using LayoutObjectNames for some required functionality. On the development system it's working fine. It returns the list of named objects on the layout.
I close the file, zip it up and send it to the client, and that required functionality isn't working. He sends the file back and I open it and get a data viewer up. The function returns nothing. I go into layout mode and confirm that there are named objects on the layout.
The first time this happened and I tried recovering the file. In the recovered file it worked, so I assumed some corruption had happened on his end. I told him to trash the file I had given him and work with a new version I supplied. The problem came up again.
This morning he sent me the oldest version that the problem manifested in. I confirmed the problem, tried recovering it again, but this time it didn't fix the problem.
I'm at a loss. It works in the version I send him, doesn't on his system. We're both using FileMaker 14, although I'm using Advanced. My next step will be to work from a served file instead of a local one, but I have never seen this type of behavior in FileMaker. Has anyone seen anything similar? Any ideas on a fix? I'm almost ready to just scrap the file and build it again from scratch since we're not too far into the project.
Thanks, Chuck
There is a known issue with the Get (FileName) function when the file name contains dots (other that the one before the extension). I will amend my answer later with more details and a possible solution (I have to look it up).
Here's a quote from 2008:
This is a known issue. It affects not only the ValueListItems()
function, but any function that requires the file name. The solution
is to include the file extension explicitly in the file name. This
works even if you use Get (FileName) to return the file name
dynamically:
ValueListItems ( Get ( FileName ) & ".fp7" ; "MyValueList" )
Of course, this is not required if you take care not to use period
when naming your files.
http://fmforums.com/forums/topic/60368-fm-bug-with-valuelistitems-function/?do=findComment&comment=285448
Apparently the issue is still with us - I wonder if the solution is still the same (I cannot test this at the moment).

LMS cmi.suspend_data not stored

I would like to store data in our ILIAS LMS with cmi.suspend_data, but the string e.g. "L_0_0_0_0_0_0_0" is not stored at all.
The commit I have done.
Tips -
Check what mode you are in cmi.mode. If you are in browse or review modes you will not be able to set any data.
Check error codes. This may give you some tip as to either the above, or other issues reported. That string is not over 64,000 characters and appears legal, so var ec = lms.GetLastError(); will get you a string code, and use that to get the message var msg = lms.GetErrorString(ec);
Keep in mind my 'lms' API example is the resolved connection to the API_1484_11 and not an actual 'thing'. So replace that with your local var.
I have a bookmarklet here https://www.cybercussion.com/bookmarklets/SCORM/ which may allow you some transparency finding out what mode you are in when viewing the content.
Good luck

LibXML: Comment-out a block of Elements

IS there a way to add/initate a comment ( e.g. $dom->createComment ... ) such that it comments out an entire block of xml tags. Basically I want to turn-off the content between the comment.
For example, it would look like this:
<TT>
<AA>keep</AA>
<!-- comment to blocking
<BB>hideme1</BB>
<CC>hideme2</CC>
-->
<DD>d's content is good</DD>
</TT>
Actually this question is a pre-cursor to my attempt to figure-out a method to be able to markup/label/identify the changes to an xml files in support of new client software functionality, but be able to have the ability to remove / back-out these xml changes in the rare event the client needs to fall back to the previous software version (and no I can't just simply point back to the original xml file because the client is allowed to make minor modifications to existing node text values). This is all going to be controlled via a perl script and LibXML's core modules (I can't use modules the client doesn't have).
So basically I've identified three possible types of xml changes as a result of new client sw functionality:
1.) ADD new element node(s) (typically to support new sw functionality)
2.) DELETE element node(s), or blocks of (would be rare, but never-the-less a possibility)
3.) CHANGE node text values (rare, but the new sw may require a new value)
For all three types, the client needs the ability to back out the changes. One thing I was thinking to use is ATTRIBUTES since the existing xml files don't use them. For example, for an ADD change type, I could include an atribute like 'ADD="sw version 4.1"' . This way if it needs to be removed, I could just simply have the perl script find those attribute strings and delete them (using LibXML methods). Same thing with CHANGE change type - I could use an attribute like CHG="newvalue_oldvalue", then again use straight perl (or LibXML) to switch back the value based on the contents of the attribute. The DELETE change type is giving me a problem though (as welll as the others lol!). I want to be able to "keep" the deleted lines in the xml file soley for the purposes if the sw falls back a version (at some late point the perl script could eventually cleanup/delete them).
I know this is a lot, I'm new to LibXML (but not to perl). I was just wonder if any of you have any thoughts as to how to go about it or seen anything resembling this kind of request ... I'd be grateful for any kind of advice! Thank you...