Upload files to SharePoint Online using SPHttpClient in an spfx webpart with the corresponding column data - httpclient

I am able to upload file using SPHttpClient in an spfx webpart to a document library. But I am not sure how to add the corresponding column data associated with the document.
For example
candidate details with a resume. Resume would be document and the details like name, email, etc would be the corresponding details in a particular row of that document library
I have referred the below link to upload document. It would be helpful if someone can add the code to update the columns too
Upload files to SharePoint Online using SPHttpClient in an spfx webpart

You need upload the file first and then update file item metadata(column values).
PnP/PnPjs is the most popular library used in SPFx and helpful for your requirement also.
sp.web.getFolderByServerRelativeUrl("your site/PnpLibrary").files.add(myfile.name, myfile, true).then(f => {
console.log("File Uploaded");
f.file.getItem().then(item => {
item.update({
Title: "Metadata Updated"
}).then((myupdate) => {
console.log(myupdate);
console.log("Metadata Updated");
});
});
});
demo thread here

Related

Domino Document to MS Word

I need to export a Domino document with RTF (images, tables, etc) to MS.Word in background mode or via Web. I have tried with POI4Xpages but I don't know how to export it.
You need to write your POI document to an output stream. This could be a fileOutputStream or the response. When using the response you need to set the header to reflect the file type. Check for XAgent for a sample how to do that. See: https://www.wissel.net/blog/2008/12/xagents-web-agents-xpages-style.html

Moodle File API : multiple rows?

In a Moodle form I perform a file upload using the filemanager element:
$mform->addElement('filemanager', 'attachment',get_string('displayedcontent', 'block_helloworld'), null, $filemanageropts);
Once the form is validated, when I record my instance in the database, I also save the uploaded file using the following function:
file_save_draft_area_files($form_submitted_data->attachment, $context->id, 'block_helloworld', 'attachment',
$form_submitted_data->attachment, array('subdirs' => 0, 'maxbytes' => 500000, 'maxfiles' => 1));
This is working fine but when I take a look at the DB table mdl_files, I saw that for my file there are 4 rows:
component fileare itemid filepath filename
block_helloworld attachment 706783489 / .
block_helloworld attachment 706783489 / test5.pdf
user draft 706783489 / .
user draft 706783489 / test5.pdf
There are 2 rows for my uploaded file in my component block_helloworld and in the component user.
One row has a filename but not the other one!
This sounds strange. Is that normal?
When I perform file deletion, how to delete all these files?
Note: I am using moodle v3.0.6
As far as I remember, this is normal behaviour. I had this issue, too, but when you cross check (like doing a file upload into a course) you will notice that there are 2 rows, too. Not sure, why but for me it was normal behaviour
The 4 entries are:
The folder that your file is in
The file itself
The folder that the draft version of the file is stored in whilst the form is being edited
The draft file whilst the form is being edited
The draft files will be automatically cleaned up after a day or so.

Get path of uploaded image in Moodle

I have added custom column to store company logo. I have used file api of moodle like :
$mform->addElement('filepicker', 'certificatelogo', 'Company Logo', null,
array('maxbytes' => $maxbytes, 'accepted_types' => '*'));
$mform->setDefault('certificatelogo', '0');
$mform->addHelpButton('certificatelogo', 'certificatelogo', 'certificate');
Once the form is submitted itemid will be stored in custom column. Say "648557354"
Now I need to get image to print logo on certificate. How can I get image path from itemid? Do I need to store any other information to retrieve image?
The itemid returned is the temporary id of the draft area where the file is stored whilst the form is being displayed. You need to copy the file into its 'real' location, when the form is submitted, otherwise the file will be automatically deleted after a few days (and it will only be accessible to the user who originally uploaded it).
I'd always recommend using the filemanager element, if you are planning on keeping the file around (filepicker elements are for files you want to process and discard, such as when uploading a CSV file data to parse and add to the database).
Details of how to use it are here:
https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#filemanager
But the basic steps are:
Copy any existing files from the 'real' area to the draft area (file_prepare_standard_filemanager).
Display the form.
On submission, copy files from the draft area to the 'real' area (file_postupdate_standard_filemanager).
When you want to display the file to the user, get a list of files stored in the file area (defined by the component, filearea, context and, optionally, itemid, you used in file_prepare_standard_filemanager and file_postupdate_standard_filemanager). You can do this with: $fs = get_file_storage(); $fs->get_area_files().
For those files (maybe only 1 file, in your case), generate the URL with moodle_url::make_pluginfile_url.
Make sure your plugin has a PLUGINNAME_pluginfile() function in lib.php, to examine incoming file requests, do security checks on them, then serve the file.
There is a reasonable example of all of this at: https://github.com/AndyNormore/filemanager

Umbraco 7. forms - path error when form transferred to document in Workflow (file upload)

I have a form with several fields that has a workflow to save as a document.
One of the fields is a File Upload.
This is matched to a document field of an Upload type.
All works well other than the File Upload in the resulting document has an error in the URL that is shown in the document:
It includes: ....umbraco/~/media/forms/upload....
Whereas it should be: ...media/forms/upload/...
The file uploaded is there, but the saved link is incorrect.
This does not seems to refer to the settings in FileSystemProviders.config or UmbracoForms.config
The later has a key for UploadStorageDirectory but has no effect.
Any suggestions would be great... John

Sharepoint 2007 Word Document opens as read only

I have a word document in a document library that when I open from a web part opens as 'Read Only' and will only let me save the document with another file name.
If I open it directly from the document library the file can be edited however I've setup a wiki page and want to be able to edit the document once it is opened from the web part.
Can I edit the document straight from opening it in from the web part hyperlink?
If you can change the WebPart. You could replace the links to the file name and make them point to this javascript function:
function editDocumentInProg(strDocument)
{
var editDocument= new ActiveXObject("SharePoint.OpenDocuments.1");
if (editDocument)
{
var newDoc = editDocument.EditDocument(strDocument);
if (!newDoc)
window.location.href = strDocument;
}
}
The Parameter strDocument would have to be your desired filename.
A little more information can be found here:
http://msdn.microsoft.com/en-us/library/dd588661(v=office.11).aspx