This project is read-only.

No files added

Feb 23, 2011 at 6:05 PM

Hey guys,

I try the following code:

BitsJob downloadJob = _bitsManager.CreateJob(order.ContentName, JobType.Download);
downloadJob.OnJobTransferred += new EventHandler<JobNotificationEventArgs>(DownloadJob_OnJobTransferred)
downloadJob.OnJobError += new EventHandler<JobErrorNotificationEventArgs>(DownloadJob_OnJobError);                  downloadJob.AddFile("""c:\\temp\\");

Unfortunately downloadJob.Files is NULL after this statement ... but why?


Feb 24, 2011 at 10:05 AM
Edited Feb 24, 2011 at 10:06 AM

Hi merlin (and hopefully other readers),

I may have a hint for you but I also have a similar problem. Try 


My problem is: I want to upload files from within a windows service. As long as I perform the following in a command line exe it works -

                        BitsJob bJob = _BitsManager.CreateJob(fnWoPath, JobType.Upload);
                        bJob.AddFile(remoteFnWithPath, localFnWithPath);

but as soon as I run the code in a service (running on my account and having access to both local and remote path) it just doesn't add a file.

Feb 24, 2011 at 10:21 AM


the files are added but not visible through job.Files.

Try BitsFiles files = job.EnumFiles(); instead.


Feb 24, 2011 at 10:32 AM
Hi merlin,

unfortunately this is not the case. I tried and again it works from
within a command line exe but not from within the windows service.
Feb 24, 2011 at 10:53 AM

Your problem is that a user must be logged on to a machine for BITS to process jobs for that user. So if you have a service that is running under a service account, it will NEVER download those files.

The way to get around this is, your service MUST run as local system, and then pass the credentials to the BITS job for access to the locations. I do this all the time and it works great.

Feb 24, 2011 at 12:35 PM
Edited Feb 24, 2011 at 12:38 PM

Hi snarfattack,

thanks a lot for your answer. But I am not sure which parameters to set
as I am not uploading to a server but to a SMB share. If don't set them
I get a System.UnauthorizedAccessException.

BitsJob bJob = _BitsManager.CreateJob(fnWoPath, JobType.Upload);
BitsCredentials cred = new BitsCredentials();
cred.UserName = "...";
cred.Password = "...";

This leads to:

Application: app.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.UnauthorizedAccessException
at System.IO.__Error.WinIOError(Int32, System.String)
at System.IO.Directory.InternalCreateDirectory(System.String,
System.String, System.Object)
at System.IO.Directory.CreateDirectory(System.String)
at LsfmFileNetworkTransferDll.BitsTransfer.workerThreadMethod()
System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()

Feb 24, 2011 at 1:42 PM

Here's my code. I'm connection to an HTTPS server and downloading to a local path.


BitsCredentials bc = new BitsCredentials();

bc.AuthenticationScheme = AuthenticationScheme.Ntlm;

bc.UserName = DomainName + @"\" + UserName;

bc.Password = Password;

bc.AuthenticationTarget = AuthenticationTarget.Server;


Feb 24, 2011 at 2:29 PM
Unfortunately this does not work with my upload to a SMB share:

"Access is denied. The error occurred while the remote file was being