Check share point if file exists in a shared document folder with power automate - sharepoint

I am trying to get the attachments of some emails and check if that attachment already exists in SharePoint. However, since the flow may have already run over some attachments that have already been received, they may or may not already be in SharePoint, so I first have to check SharePoint if the attachment exists and if they don't, create the file using the email attachment content.
So what I have so far is replicating a process that was described here
The problem that quickly arises is that under "Get file content using path" action, the File Path input box(circled below) won't let me append a file path that isn't currently already in a document folder.
Not sure if this is still a valid way to accomplish it or if there's another way. I have checked all over the place and still haven't been able to find a solution. If there's anybody that can help it would be greatly appreciated!!

To tackle this what you can do is to create a variable using Initialize variable action and compose the path e.g. '/DocumentLibrary/file.ext' that you want to check if exists. then you can refer to that variable in your folder path box for Get file content using path action. Please see the screenshot:
Next you can configure run afterfor file creation action and create file if Get file content using path action has failed, otherwise do other stuff that is required. I have tested this for sending different emails based upon file found or not found and it works well.
Hope this solves your issue.

Related

Revit API - Finding the path of nested links

I am trying to find the file path of nested links and ran into a problem.
I am interested in the 2nd level, meaning finding the file path of a link inside one of the links in the file that I currently have opened.
My problem is where the reference Type is Overlay, if reference type is Attachment I don't have a problem.
I am also assuming the files are in BIM360 cloud, but I believe I have the same problem if the files were local.
I am able to get the RevitLinkInstance and RevitLinkType object for those links.
However, if I try to use GetLinkDocument() on the RevitLinkInstance I get null, and trying getting the InSessionPath using GetExternalResourceReferences() on the RevitLinkType get me "Autodesk Docs://" and stops there without the real path.
Will appreciate any help including letting me know if this is at all possible.
Thank you,
To my knowlegde it is impossible to get the link within a link through one Document. This is because with Overlay the link is not stored into the Link. That is also why it works with Attachment. Because Revit than makes it a point to store the Link in that file and thus it is part of that Revit file.
What you could do instead is search for the file path of the first link. Then use the file path in the OpenAndActivateDocument(string filepath) method. Repeat the first step to get all RevitLinkInstances of this Document. You can get the needed information from this link, store it in a variable and close the link document.
If an example is needed please let me know.

saving mail attachment with PowerAutomate to sharepoint corrupts the file

I am trying to build a flow based on the PowerAutomate template
Create Planner task and add attachments to SharePoint on new email
arrival
This template works fine, in that it saves all the mail attachments to my sharepoint. But it only shows the link to the last attachment in the task.
I have worked around it, by adding a string variable and appending all the sharepoint paths to this variable.
With my Flow, everything runs smoothly. But the stored files are about 10%- 20% bigger in size than the original and they turn out to be corrupted.
The only difference I can spot in the saving of the file is as follows:
Template section has "get attachment" and the according "body('get attachment'):
While my in my version I can only select "get attachment (V2)" and the corresponding "body('get attachment (V2)')
There is an option with V2 that allows or disallows chunking, but there is no effect on my filesize.
The other difference is, that I have my flow create a different folder based on the task ID, since there where errors, if the same name attachment came a second time. But I have tried my flow without the added folders and there is no difference in file size.
The original files:
and the corrupted files:
It makes no difference if I use the sharepoint link provided through the flow to my new planner task, or if I open the files directly within sharepoint. The result is an error.
Can anyone guess, why my flow seems to store something more within the file and thus corrupting it? I can provide the other parts of the flow in more detail too. Here is the overview of my custom flow:
I actually found the answer after rewriting it from scratch:
Using the old template had me looking for the wrong information when adding the attachment content to sharepoint. I had always searched for "body" which was used in the template and gave me this
But searching for attachment the dynamic content actually showed me the right pieces. I am not sure, if I missed it before, or if recoding a template hid them somehow. With the rewrite from scratch I found this:
So, to make a long story short: Use "Content Bytes" of the "Get_Attachment_(V2)" Method and everything works fine.

Issue Getting Attachments from Email in Microsoft Flow/Power Automate

I'm currently building a new ticketing system for my workplace. When an email is received it generates a ticket number and few files in a SharePoint document library. One of those folders is "Attachments" where the flow I am building is supposed to put any attached documents. As far as I can tell I've followed other guides to the tee, however it renders the attachments un-openable. After downloading the files it did make and opening them in Notepad++, the content of the files is completely different and I can't seem to figure out why... I've been testing mostly with *.docx files, but it does the same for other file types as well. Please see attached screenshot of the attachments getter part of the flow. Any support is greatly appreciated!
Attachment Getter Screenshot
Note: This is how the guides told me to do it, however I did try changing the "File Content" box to "Attachments Content" instead of "Current Item" from the dynamic content menu to no avail.
Try use attachments content directly:
How to save Email Attachments to your SharePoint Document Library
Can you try to get the file content.
File content should help getting attachment. You will have to recreate a file though.
For this problem, please check if you have set the value of Include Attachments in the trigger to Yes.

How to write a workflow to move the files from one folder to another (in the same doc library)?

I've a document library. Within this library, I've two folders. I'd like to run a workflow which moves the file from one folder to another when an item is changed. I'm using update list item action. can anyone please tell me, how to write the path and name with full workflow? Thanks :)
You should call rest api(post request) to move file.
Sample endpoint:
/_api/web/getfilebyserverrelativeurl('/mydoc/testdoc.txt')/MoveTo(newUrl='/mydoc2/testdoc.txt',flags='1')
Call rest api in workflow.
https://cann0nf0dder.wordpress.com/2017/06/26/sharepoint-designer-2013-workflows-and-post-rest-api/

How to rename SharePoint document and create a new version if the specified file name is already in use?

I need to rename an uploaded document by adding some additional information to its file name, currently I do this with an Event Receiver ItemAdded wiring up on Document Library, using code
SPListItem material = properties.ListItem;
material["Name"] = RenameFile(material["Name"].ToString());
material.Update();
//material.UpdateOverwriteVersion(); //same issue
This would works fine until the same file is uploaded again, after renaming the error "the specified name is already in use" will occur although I have enabled document version control.
Do I need to create a new version programmatically? if so, how am I supposed to do it, can someone shed some lights on this? Any help is deeply appreciated.
This may be of some help
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/1f003923-dc88-427b-a6b8-34c3616d5b1a/
I think you need to check the document out and then back in

Resources