Unable to Update Sharepoint Document Properties: Required Fields are Empty - c#

I am updating Documents on Sharepoint using the List.asmx web service.
But problem I am facing is:
Fields are not getting updated as some of required fields are not added.
But to fill required fields I have to Update again.
"ID" field is compulsary at the time of Update.
Which we get only after uploading Document. (We get this id by "ows_id" attribute value.)
Edit: As said by "Janis Veinbergs" We can't get this ID until document is actualy saved.
So how will I update document as ID field is must for Update?
If I don't Put ID Field:
Error : 0x8102000aInvalid URL Parameter
The URL provided contains an invalid Command or Value. Please check the URL again.
If I put Null Value to it:
Error :0x81020016Item does not exist
The page you selected contains an item that does not exist. It may have been deleted by another user.
Is there any way to set document properties at the time of uploading files on Sharepoint?
****Note: I am uploading file in Chunck.And Not using Microsoft.sharepoint.dll ****
Language: C#.
I tried this code.
But here again properties are being set after uploading file.

number 2 -> One is for sure - you can't get database row ID of document before it is actually saved into database.

The page linked to in the question actually links to a newer option using a FrontPage RPC method to post documents to SharePoint:
http://geek.hubkey.com/2007/11/upload-file-to-sharepoint-document.html
I would use that instead.
If you need to upload multiple files, you can use this method. If you need to upload one file, try this one.

Related

Reading task enterprise custom field values from mpp file using mpxj

I'm trying to read task details from a mpp file using net.sf.mpxj library. However, when trying to read custom fields, I get a byte array which I do not know what to do with! It is not the exact value of the custom field from that specific task. Can anyone tell me what to do?
ProjectReader reader = new MPPReader();
ProjectFile project = reader.read(#"C:\EPM\test2.mpp");
foreach (net.sf.mpxj.Task task in project.Tasks)
{
var Value = task.GetFieldByAlias("My Custom Field Name");
}
The "Value" will be a byte array and I do not know how to get the real value from it.
UPDATED ANSWER:
As of MPXJ 10.7.0 you can retrieve correctly typed values for enterprise custom fields. You'll also find a CustomFieldDataType attribute as part of the CustomField class which indicates what type you'll be retrieving.
(One interesting "gotcha" is that if your MPP file contains an enterprise custom field which is based on a lookup table, i.e. the user can only select from a fixed set of values, the user-visible text is NOT stored in the MPP file. You'll only get back a GUID representing the value the user has selected. Microsoft Project itself has this same issue... if you open the MPP file when you're not connected to Project Server, these values will appears as blanks...)
ORIGINAL ANSWER:
The main problem is unfortunately that MPXJ doesn't currently offer the same level of support for Enterprise Custom Fields as it does for other fields. While it is able to identify Enterprise Custom Fields and the aliases they've been given, at the moment it is only able to read the raw bytes representing the field data.
Enterprise Custom Fields are not as commonly used as other field types so there hasn't been as much time invested in locating the definitions of these fields in the MPP file. The field definition will contain the type information necessary to convert from the raw bytes to the expected data type.
Improved support for Enterprise Custom Fields is on the "to do" list for MPXJ.

How to apply a multi-document template

The general process
Documents are uploaded to DocuSign creating a new Envelope.
Templates are applied to this Envelope.
Recipients are updated to make sure there is no mixup with signers from the template
The Envelope is sent to the signers.
Intended use of templates
The primary use of templates is to allow users to upload documents and use all other information from templates like fields and other setting for the uploaded documents. Signers can also be freely set and overwrite the ones defined in the template.
For applying templates we use https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopetemplates/applytodocument/
The Template
The template consist of 2 documents. The first document has 3 pages and the second document has 2 pages.
There is one signer. A signature box is added to the last page of both documents.
The Problem
Test scenario: The exact same documents as in the template. This results in the signature box on the second document is not set.
Test scenario: Use the 3 page file for both documents. This results in the signature box being put on page 3 of both documents. So it looks like the assignment works only from document 1 to all the other documents
Test scenario: Use different 3 page documents that match the template for both documents. The result is the same as in the 2. test scenario.
What I tried
The described scenarios are based on this (simplyfied) code for applying the templates:
//variables envAPI (class EnvelopesApi), accountId, templateId and envelope (class Envelope) are already set
DocumentTemplateList templateList = new DocumentTemplateList();
templateList.DocumentTemplates = new List<DocumentTemplate>();
templateList.DocumentTemplates.Add(new DocumentTemplate()
{
TemplateId = templateId,
DocumentId = "1"
});
envAPI.ApplyTemplateToDocument(accountId, envelope.EnvelopeId, "1", templateList);
templateList = new DocumentTemplateList();
templateList.DocumentTemplates = new List<DocumentTemplate>();
templateList.DocumentTemplates.Add(new DocumentTemplate()
{
TemplateId = templateId,
DocumentId = "2"
});
envAPI.ApplyTemplateToDocument(accountId, envelope.EnvelopeId, "2", templateList);
//some recipient checking is done here
envAPI.Update(accountId, envelope.EnvelopeId, envelope);
I also tried using more entries in templateList.DocumentTemplates but that only caused INVALID_REQUEST_BODY errors.
I realized the DocumentID property of the documents in the templates are very different after the first file. My test template has 1 for the first document and the ID of the second document is a very large number. Using this large number also causes INVALID_REQUEST_BODY errors.
Is this actually correct and the error is somewhere else? Because it looks like it should work this way. Or is the problem located somewhere else?
The workflow that you are trying is a perfect place to use a composite template. The recommendation is use one composite template per document. In one POST envelopes call you can swap out the documents on the templates with documents at runtime and apply server (saved) templates to the documents. You can add recipients, drop recipients by not including them, and also add tabs or write values to tabs at runtime. See:
https://www.docusign.com/blog/dsdev-from-the-trenches-composite-templates
https://www.docusign.com/blog/dsdev-why-use-composite-templates
To answer my own question: This doesn't work. At least not this way.
Yes, composite templates are one way of dealing with this requirement but then again, why do multi-document templates even exist?
So the answer is quite simple: Do it the other way around.
To use a multi-document template properly, the template needs to be the starting point. Use a template and replace the files to create an evenlope instead of creating an envelope first and then applying templates to the envelope.

How to rename a PDF field when a duplicate field name exists using iTextSharp & C#

Goal: My intent is to help a user outside of my organization upload any multipage PDF that has multiple fillable fields inside of PDF document where some of the fields were unknowingly tagged with the same name. If the users were internal we could request that they tag the PDF with unique names but we don't have that luxury in this case. We need to find and fix issues using iTextSharp without bothering the user and/or partially detecting their tagged fields.
Current State: What happens today when using iTextSharp is that only distinctly-named fields are detected. Fields that are using identical names as others are "ignored" for all intents and purposes.
Example: I have a PDF with three tagged fields named as follows: One, One, Three. When I run the PDF through iTextSharp, it is only picking up two AcroFields (One and Three). The second field named "One" is not in the AcroFields collection. What is interesting is that all three fields ARE in the AcroForm.Fields collection but has limited MetaData information about each field. The information I can access within the AcroForm.Fields items are "/DA, /DR, /FT, and /T". None of these have what I am looking for (below).
Question: I have code to add a new field to the AcroFields collection and it is working but I am missing information about the second "One" field and need to pull key information such as height, width, page number, x, y coords of where that field was. My plan is to dynamically add the missing AcroFields back into the document such that the textbox is positioned correctly and is the appropriate size when the user sees it later. The end result would be that the user sees no visual difference, isn't notified of issues, and is fully corrected by implementation I am working on.
Thoughts or suggestions?
Of course, if I have missed anything in this question or if the approach is wrong please advise.

Retrieve 'Last Saved By' file property programmatically

I'm trying to access the 'Last Saved By' file property using C# as part of an MVC web app. I'm able to get pretty much every other property on the file from last modified date, to the owner and I've even used Shell32 to get really obscure properties.
However, I cannot find a way to get the 'Last Saved By' property when I am retrieving the audit properties for each file that I need to report on. The files I need to get this data from are all Excel.
The 'Last Saved By' property can be read using the WindowsAPICodePack.Shell libraries. This property is application specific, so it is not present on some files (for example it is available on .xls but not .csv). The 'Last Saved By' file property is named 'LastAuthor'.
I used nuget to get the package and the code below to access the property:
string lastSavedBy = null;
using (var so = ShellObject.FromParsingName(file))
{
var lastAuthorProperty = so.Properties.GetProperty(SystemProperties.System.Document.LastAuthor);
if (lastAuthorProperty != null)
{
var lastAuthor = lastAuthorProperty.ValueAsObject;
if (lastAuthor != null)
{
lastSavedBy = lastAuthor.ToString();
}
}
}
You can access the property in
Workbook.BuiltinDocumentProperties(7)
Maybe it will have index 6 when accessed from the C#. See MSDN documentation.
Quick verification: in Immediate Window (Ctrl+G) of Excel VBA editor (Alt+F11) you can type
? ThisWorkbook.BuiltinDocumentProperties(7) and hit Enter to display the property. This is the Excel part.
There is also part how to call Excel from the C#, but I am not going to cover this one, you can find literally hundreds of answers and examples on this topic.
Maybe even more effective can be just adding reference to Microsoft.Office.Tools.Excel Namespace and working directly, without Excel.

Loading a Null String and Silverlight 4

I maintain a Silverlight 4 application. While I was out of the office, the database structure was changed and a table was dropped and its fields combined into another existing table. Now, I’m receiving the following error after I create a new item and proceed to its "summary" screen:
“Value cannot be null. Parameter name: Text
At System.Windows.Controls.TextBox.set_Text(String value)”
This only happens with newly created entries, not older entries where the information on the next screen is complete (data was converted from an Excel spreadsheet and loaded into the database). So, I’ve narrowed it down this: the child window that is used to create a new record doesn’t have all the fields that were added to the table because some of the information isn’t available when the record is created. A Google search turned up that null strings can’t be passed in Silverlight.
The Summary screen is loaded via ddsSummaryLoadedData domain service. If I don’t include the “new” fields, then the values aren’t loaded for existing entries, but new entries don’t cause an error. If I do include them, older entries load correctly but new ones give the above error.
Is there a workaround to create the empty fields until they’re needed, but still load data if it exists (for older entries)? Or does the child window need to be redesigned? I’m new to Silverlight and still have so much to learn!
It doesn't look like you're using Bindings to render your view otherwise null values will be handled gracefully, so if you are setting the Text property manually in code, use the cascading operator to verify you are not submitting a null value.
myTextBox.Text = myModelValue.FirstName ?? string.Empty;

Categories

Resources