How to add custom column in outlook while using DocumentItem - c#

I am developing VSTO addin using C#.
Here, I have drag one file from my PC to outlook folder. It displays in outlook as show in picture.
Now I want to add one column in that folder.
I have done some code to add custom column in folder. It will display in picture. Column name is ABCDEFGHI.
I want to update the value of ABCD.pdf file property.
As per outlook ABCD.pdf is a DocumentItem. I want to add my custom property for that file, to display in view.
This is my sample code.
UserProperties objUserProperties = objItem.UserProperties;
UserProperty objUserProperty = objUserProperties.Add("ABCDEFGHI", OlUserPropertyType.olText);
objt.Value = "YYYY";
This will give me an error.
Error:

If you take a look at the UserProperties.Add method description in MSDN you can see the following description:
You cannot add custom properties to Office document items such as Word, Excel, or PowerPoint files. You will receive an error when you try to programmatically add a user-defined field to a DocumentItem object.
Instead, I'd recommend creating any Outlook item and attaching a document to it. Following that way you will be able to customize the View by adding user properties as you need.

Related

How to prevent Excel from showing the Chart Design ribbon when programmatically switching sheets

I'm building an Add-in for Excel 365 and need to be able to programmatically switch the activated sheet of a workbook. This is easy and currently done using the following code:
sheet.Select();
Here's an example:
However, in case the sheet is a Chart (in the figure Chart1), and that chart is selected for the first time, Excel automatically switches from my custom Add-in Ribbon tab to the built-in Chart Design tab in the ribbon. By doing so, the user looses the custom tab, which is a usability issue for them.
Here's an example of how the ribbon looks like after I call sheet.Select():
Question: Is there a way to prevent Excel from switching the tabs, or otherwise, revert that change?
I tried calling ActivateTab, but upon invocation, that method always throws an ArgumentException with the following message:
Value does not fall within the expected range.
This is the code I use inside my Ribbon component:
var tab = this.Tabs.First();
var controlId = tab.ControlId;
var id = controlId.ToString();
this.RibbonUI.ActivateTab(id);// throws value does not fall within the expected range
You can use the ActivateTabMso method to activate the ribon tab again:
this.RibbonUI.ActivateTabMso("TabAddIns");

how to copy the text from textbox and paste on outlook message body

I tried to develop an Outlook add-in to ask users for information by showing a Windows Form with several TextBox controls. The text (includes name, phone, email address etc) user input will be added in the Outlook mail body as signature.
Just wonder that how can I get all the data user entered and paste them on the Outlook mail body? Can i just copy them all on the clipboard and paste into the body? Still cannot find a proper method to achieve this, could you give me some suggestions?
You can defined public methods and properties on your Windows form for getting the values an user entered.
The Outlook object model provides three main ways for working item bodies:
Body - a string representing the clear-text body of the Outlook item.
HTMLBody - a string representing the HTML body of the specified item.
Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.
You can read more about all these ways in the Chapter 17: Working with Item Bodies. It us up to you which way is to choose to customize the signature in the message body.
To get the active inspector window use the ActiveInspector method of the Application class. The method returns the topmost Inspector object on the desktop. The CurrentItem property returns an Object (it will be a mail item in your case) representing the current item being displayed in the inspector.

Allow the user to upload a document to the application

Using Orchard CMS V 1.6 I would like to implement a feature which (1) allows the user to upload a document (2) stores the date it was uploaded (3) Stores the id of the record uploaded
Is there a part for doing this.
I've no idea how to go about this....any suggestions welcome...thanks
EDIT
As I'v said i've used your advice to create a content type.
Then created a custom form and tried to add that content type(the media) to a custom form.(as explained on the link you provided http://devdirective.com/post/160/how-to-create-custom-forms-in-orchard-cms-with-email-and-recaptcha)
however when it appears on screen on the front end the mediaPicker box appears but it is greyed out and doesnt allow me to select it. 'Browse' and 'clear' also do nothing....Also how can i remove the option of the permalink
thanks
Create a new content type with whatever name you want eg. MyFileUpload
Add the Title, AutoRoute and Common part (common part will store the date the content item was created)
Add a field and select the Media Picker Field (you can limit extensions to only allow .doc files if you wish and make this field required)
Something like that should work :)

How to build custom sentences with OpenXML

I would like to know if there is a way to "play" with sentences in a .docx.
Here's what I need to do:
I have a paragraph in a document
exemple of my paragraph:
This is a paragraph that I need to format based on some conditions and I can't figure how to do this with openxml sdk.
end of exemple.
So based on a condition that I evaluate in c# I would like to add/remove the text. Another thing that you should know id that I would like the product owner to change the text of the document.
Basicly what I want to acheive is having a template document that my product owner can edit at will but in this document the text might change based on for whom the document is produce.
Thanks
You can create a template document in Word and create a content control in each place you want the text to be dynamically inserted. For each created content control, you should set unique Tag property value.
In your c# application code, you can then find a content control by its tag quite easily. After you find it, you can save its parent node, remove the content control and insert the text you want as a child paragraph element for the parent node saved earlier.
You can add content controls by using Developer tab. If you can't see it, you can use steps described here in order to show it: http://msdn.microsoft.com/en-us/library/bb608625.aspx .
There are some complexities involved in replacing text because text can be broken into multiple runs. If you want your owner to be able to edit the document, this is a problem you must solve. Luckily, there is sample code that you can use as part of the PowerTools for Open XML. PowerTools were written as cmdlets for PowerShell, but you can take the core C# code for your own programs. The TextReplacer.cs module should give you a good starting point. You will need some of the other modules that it depends on, like PtOpenXmlDocument.cs, PtOpenXmlUtil.cs and PtUtil.cs. I hope that helps.

How to build form completion/document merge application with Winforms or WPF?

I need to build an application that accepts user input data (such as name, address, amount, etc.) and then merges it with a pre-loaded document template (order form) and then prints this merged document. I can use Windows Forms or WPF for this project.
Any suggestions on how best to approach this? I'm experienced with Winforms development, but don't have any idea how to handle merging the data to the document for printing.
WPF works great for this.
You can create document templates from WPF UI elements such as a Page or a UserControl. Set up the template like you'd set up any UI in the VS designer. Determine what shape your data will be stored in (this will be your DataContext), then bind against its public properties. Then you can drop your merged template into a FixedPage and add it to an XPS document. You can print that very easily or save it to disk.
Simplified algorithm:
Create a data entry form.
Create a type that will hold data from the form (call this type Foo)
Create a Page template that binds against Foo (when a Foo instance is the DataContext)
Bind the form to an instance of Foo
Have the user fill in the form (and thereby the instance of Foo)
Create an instance of your template (assume its a Page)
Set Page.DataContext = fooInstance;
Add the Page to a FixedPage, then add this to a Fixed Document
Save the FixedDocument to an XPS document
Save the XPS document or send it to a PrintQueue
I'm doing something similar to this and it works well. Just go to my profile and read all my questions. They cover most of the hard bits of the whole procedure.
You need to use Mail Merge. A mail merge is a method of taking data from a database, spreadsheet, or other form of structured data, and inserting it into documents such as letters, mailing labels, and name tags. Start from this article.

Categories