Getting Started with

Dec 29, 2010 at 3:32 PM

Hey there---

I am wondering if anyone has a get started documentation guide for using the wrapper. I have a project that could benefit from this wrapper, but working with BITS is totally new to me and I would love to have something to follow.

Thanks for anything you can throw my way.


Dec 29, 2010 at 4:13 PM

I don't have a getting started guide but I can send you some example code that I got working.  Also, the events don't work properly in the copy I downloaded so I had to modify the code a little to get it to work.  I am not using the library anymore but I may have the code hanging around somwhere.  It's really not that involved.

Dec 29, 2010 at 4:18 PM

In fact, I just found it.  Here is my code for initiating a job to upload to the server.  sorry I don't have any download examples, we didn't need that part.  I have removed some of the unecessary code to focus more on the bits part.

 public void CreateAndLaunchUpload(string fullLocalFilePath, string remoteStorageDirectory, uint minimumRetryDelay)
                var manager = new BitsManager();

                var scanJob = manager.CreateJob(fullLocalFilePath, JobType.Upload);
                scanJob.MinimumRetryDelay = minimumRetryDelay;

                var localFilenameOnly = Path.GetFileName(fullLocalFilePath);
                var fullRemotePath = Path.Combine(remoteStorageDirectory, localFilenameOnly);

                scanJob.AddFile(fullRemotePath, fullLocalFilePath);

                // Add the success event so that we can clean up.
                scanJob.OnJobTransferred += new EventHandler<NotificationEventArgs>(scanJob_OnJobTransferred);



         void scanJob_OnJobTransferred(object sender, NotificationEventArgs e)


Dec 29, 2010 at 5:44 PM

Hey JS... thanks for the reply... that code snippet will help. And I also found this article on looks like by the same author of the wrapper classes..., so I am working with the code now to try it out. Our project is for downloading files from the server, but in comparing your code with the code from CodeProject, it looks like a similar code base. Thanks again!


Dec 29, 2010 at 6:02 PM

Hey JS---

In working with the code, by setting a breakpoint I see the OnJobTransferred handler picks up when the Resume code completes, but two things are happening. One is that the file does not appear as I have designated it to be downloaded (C:\Temp directory), I am only getting a *.tmp file with a BIT prefix followed by an alphanumeric string (e.g. BIT485C.tmp, or BITC74C.tmp) where it should be a file named test.docx (the file to get downloaded is a docx document), and the second piece is that once the code enters the handler's scope, I get an InvalidOperationException saying "The calling thread cannot access this object because a different thread owns it." Inside the handler, I am simply assigning a value to a label control indicating the "file has been downloaded".

Do files downloaded through the sharpbits have to get converted somehow from *.tmp to their desired file format?

Dec 29, 2010 at 7:08 PM

Again, I only have upload experience.  What I found was that the strangely named file was a temp file that BITS uses to store the info until the file comes fully in.  We had a dir monitor app looking for the file so it doesn't appear until it is fully uploaded.  i think that is a side effect of BITS not specifically SharpBITS.


Dec 29, 2010 at 7:39 PM

Cool... that is good to know... thanks again for your insights.


Jan 3, 2011 at 2:47 PM

Hey Scott---

Happy New Year to you... I am wondering if I can run something else by you... I have the BITS code working now to pull a file down from a server onto a local machine. I am wanting to discover the file size of the file that will be downloaded via the job.Files array (job.Files[0].Progress.BytesTotal) or by simply using the overall Progress property of the job object itself (jobs.Progress.BytesTotal), but I can't seem to determine when the Files array is populated with the file in order to tap that info and the Progress property of the job object stays at 0. Did you have the need to tap that info with your uploading process?

It seems like it would be available after the job.AddFile() method is called, or at least after the job.Resume() method is called, but when I set breakpoints for those lines, I still see a null value for the Files array.


Jan 3, 2011 at 3:19 PM

I just figured it out... I needed to tap that value from within the DoWork delegate of the BackgroundWorker object I have rolling with the application.

May 12, 2011 at 5:39 PM

I was able to build the SharpBITS.Base project, but adding a reference to SharpBITS.Base.dll to any project in Visual Studio 2008 shows the DLL with the "!" icon. Attempting to open or get properties of the DLL results in "This project cannot be viewed in the object browser because it is unavailable or not yet built". Any reference to SharpBits.Base in my projects results in "The type or namespace name 'SharpBITS' could not be found."

I have tried Clean builds of SharpBITS.Base and my projects. Target Framework for all projects is .Net 3.5.