Download File Into Specific Folder

I want to download a file from google into a particular folder and save it with a particular name. Can anyone help on the same with a solution?

Please refer to the attached Screenshot.


You can download using HREF,

  1. Get the HREF of your file which you want to download it from google using “Get attribute” activity and store it into one variable, in here i am storing my href into “downloadaudio” variable

  2. Add this code into Invoke code acitivity

Using wc As New System.Net.WebClient()
    End Using
  1. create arguments in this acitivty like following:

Make sure you are passing same arguments in your code…
4) Pass your HREF variable into URL arguments value and set your desire path into PATH arguments value

Hope this will work for you

Vinit M

1 Like

Hi, Sarah! Welcome to the community.

Can you explain your task in more detail?)

Hi @Sarah_Syed welcome to UiPath Forum

Please find below link for reference to go to download settings in chrome

So I understand you are downloading something from Google

So in download settings there will be an option named :Ask where to save the file everytime

Kindly enable that radio button so you will be able to download the file to your desired destination location

Thanks @nikhil.girish .

Thanks @Vinit_Mhatre , that’s something new to me!

Hi @Sergey_Petrenko ,

The process is that I have to generate some document from Google and save it in a particular folder in “Downloads”.
"This PC\Downloads\Extract1\Extract UiPath1"
But the problem is I’m unable to give the path in the Save As - window using UiPath Studio Activities. (Even after enabling “Ask where to save the file everytime” in Google settings)


Please try to insert path to “File name” field.

C:\This PC\Downloads\Extract1\Extract UiPath1\file.pdf

And then click “Save”.

Great response, works for me and looks like an elegant way to achieve this goal. One more question for me, can the code be modified to create a folder if it doesn’t exist?

Hello @Tadas - Is it not creating the folder if it doesn’t exists??


No it throws an error for me… if I assign a path with just a file name it downloads it to my project folder. workflow attached
DownloadFile.xaml (10.3 KB)

RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.Net.WebException: An exception occurred during a WebClient request. —> RemoteException wrapping System.IO.DirectoryNotFoundException: Could not find a part of the path ‘C:\Users\xxxxx\new\new.docx’.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access)
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
— End of inner exception stack trace —
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at System.Net.WebClient.DownloadFile(String address, String fileName)
at UiPathCodeRunner_b8c7bddc7cc942b6af5b8475b95614e2.Run(String url, String Path)
— End of inner exception stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object providedArgs, ParameterModifier modifiers, CultureInfo culture, String namedParams)
at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object args)
at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode, List1 inArgs, IEnumerable1 imps, Object args)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Before saving the file, you’d have to use an If with NOT Directory.Exists(yourPath) as the condition, and then in the Then you create the folder. Again, do this before you click whatever you’re clicking to download the file.

Hi @Vinit_Mhatre,

I tried your suggestion but getting the below error. Can you check and advise?

“Invoke code: Exception has been thrown by the target of an invocation.”

Kind regards,

Hi @Karunamurthy

Try printing your arguments; this error occurs when the arguments contain blank data.

Vinit :slight_smile:

Hi @Vinit_Mhatre,

Sorry, I am unable to understand “Try printing your arguments”. Can you please elaborate it further?

I want the text file to be downloaded from the “Browser” to particular folder “Data\Output”.

Thank you for the help!

Kind regards,

What if you don’t find Href attribute in my case equals #