Click here to Skip to main content
11,804,008 members (75,949 online)
Click here to Skip to main content

Simple Upload File to Rapidshare Account Method using C#

, 2 Apr 2009 GPL3 57.7K 821 32
Rate this:
Please Sign up or sign in to vote.
By using this C# (.NET 2.0) method, you can easily upload your files to account


By using this class, you can easily upload your files to

With RapidShare, you can send big files easily and in a secure manner.

This class supports the following type of Rapidshare accounts:

  • Premium accounts (type = 1)
  • Collector's accounts (type = 2)
  • Free users (type = 0)

After Selecting the file and uploading, you should see two links in the result Panel, one for downloading and one for deleting the file from

Using the Code

You can see the full usage of this class in the source of the demo application.

For this application, I'm using Rapidshare version 1 API (the original API is made by Perl).

class QRapidshare
        public string QUploadToRapidshare(string FilePath, string username,
            string password, int AccountType)
            FileSystemInfo _file = new FileInfo(FilePath);
            DateTime dateTime2 = DateTime.Now;
            long l2 = dateTime2.Ticks;
            string s1 = "----------" + l2.ToString("x");
            System.Net.HttpWebRequest httpWebRequest = GetWebrequest(s1);
            using (System.IO.FileStream fileStream = new FileStream(_file.FullName,
                FileMode.Open, FileAccess.Read, FileShare.Read))
            {//Set Headers for Uploading
                byte[] bArr1 = Encoding.ASCII.GetBytes("\r\n--" + s1 + "\r\n");
                string s2 = GetRequestMessage(s1, _file.Name, username, password,
                byte[] bArr2 = Encoding.UTF8.GetBytes(s2);
                Stream memStream = new MemoryStream();
                memStream.Write(bArr1, 0, bArr1.Length);
                memStream.Write(bArr2, 0, bArr2.Length);
                byte[] buffer = new byte[1024];
                int bytesRead = 0;//Read File into memStream.
                while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                    memStream.Write(buffer, 0, bytesRead);

                httpWebRequest.ContentLength = memStream.Length;

                Stream requestStream = httpWebRequest.GetRequestStream();
//Send File from memStream to
                memStream.Position = 0;
                byte[] tempBuffer = new byte[memStream.Length];
                memStream.Read(tempBuffer, 0, tempBuffer.Length);
                requestStream.Write(tempBuffer, 0, tempBuffer.Length);
            string tm = "";
            using (Stream stream = httpWebRequest.GetResponse().GetResponseStream())
            using (StreamReader streamReader = new StreamReader(stream))
                tm = streamReader.ReadToEnd();

            }//Get Response from Rapidshare and Return the Links.
            return tm;

        private string GetRequestMessage(string boundary, string FName,
            string username, string password, int AccountType)
//Generate Headers exactly Like Rapidshare API v.1.0
            System.Text.StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("Content-Disposition: form-data; name=\"toolmode2\"");
            if (AccountType != 0)//Free User
                if (AccountType == 1) //Premium Account
                        "Content-Disposition: form-data; name=\"login\"");
                else //Collector Account
                        "Content-Disposition: form-data; name=\"freeaccountid\"");
		("Content-Disposition: form-data; name=\"password\"");
            }//else if Free User
//File Name
            stringBuilder.Append("Content-Disposition: form-data; name=\"");
            stringBuilder.Append("\"; filename=\"");
//File Type
            stringBuilder.Append("Content-Type: ");
            stringBuilder.Append("Content-Transfer-Encoding: ");
            return stringBuilder.ToString();

        private CookieContainer _cockies = new CookieContainer();
        private HttpWebRequest GetWebrequest(string boundary)
        {//Prepare for Uploading 
            WebClient wc = new WebClient();
            Uri url0 = new Uri( 
            int uploadserver = int.Parse(wc.DownloadString(url0).Trim());
            //Find Free Upload Slot on Rapidshare servers.
            System.Uri uri = new Uri("http://rs" + uploadserver + "l3" +
            System.Net.HttpWebRequest httpWebRequest = (
            httpWebRequest.CookieContainer = _cockies;//Set Cookies for rapidshare
            httpWebRequest.ContentType = "multipart/form-data; boundary=" + boundary;
            //Set Fake userAgent exactly like Rapidshare Manager
            httpWebRequest.UserAgent = "RapidUploader[v1,2]";
            //Set Fake Referer
            httpWebRequest.Referer = "";
            httpWebRequest.Method = "POST";
            httpWebRequest.KeepAlive = true;
            httpWebRequest.Timeout = -1;
		("Accept-Charset", "iSO-8859-1,utf-8;q=0.7,*;q=0.7");
            httpWebRequest.Headers.Add("Accept-Encoding", "identity");
            httpWebRequest.Headers.Add("Accept-Language", "de-de;q=0.5,en;q=0.3");
            return httpWebRequest;
//You can use this class in .NET Web, Window, WebService,...

In the next version, I want to add an Upload Speed Control and Progress Bar.

You can upload up to 2000 MB file to your Premium account, and up to 200 MB for Collectors account and Free users.

Points of Interest

You can also use this method for your web applications and dynamically upload your files to your account.


  • 2nd April, 2009: Version 1.0


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Ghasem Heyrani Nobari
Software Developer (Senior)
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
Ghasem - Heyrani-Nobari

You may also be interested in...

Comments and Discussions

QuestionUpdated the code Pin
Member 80246504-Oct-12 7:24
memberMember 80246504-Oct-12 7:24 
AnswerRe: Updated the code Pin
RKillaars25-Mar-13 6:00
memberRKillaars25-Mar-13 6:00 
QuestionDoesn't work for me Pin
Mr.Extremer30-Mar-11 23:39
memberMr.Extremer30-Mar-11 23:39 
AnswerRe: Doesn't work for me Pin
Ghasem Heyrani Nobari30-Mar-11 23:53
memberGhasem Heyrani Nobari30-Mar-11 23:53 
GeneralRe: Doesn't work for me Pin
Mr.Extremer31-Mar-11 0:11
memberMr.Extremer31-Mar-11 0:11 
GeneralRe: Doesn't work for me Pin
ShoaibRiaz13-Apr-11 19:02
memberShoaibRiaz13-Apr-11 19:02 
Respected Sir, i got that lot of things have been changed on rapidshare, but please try make it better now again and make your this uploader application more efficient. it was really awesome and brilliant work and saved a lot of time of browsing. So please change it again and make it perfect and workable. Now this application is not working (uploading files)
when we want to upload file, it gives message after a few moments, "savedfiles=0 forbiddenfiles=0 premiumaccount=0"
so please look forward to it.
GeneralThx for your nice code , but premium doesn't work anymore Pin
Siedlerchr15-Aug-10 8:37
memberSiedlerchr15-Aug-10 8:37 
GeneralRe: Thx for your nice code , but premium doesn't work anymore Pin
vsisman30-Aug-10 4:48
membervsisman30-Aug-10 4:48 
GeneralUpload more than 200mb Pin
Jose Carlos Ribeiro3-Feb-10 0:06
memberJose Carlos Ribeiro3-Feb-10 0:06 
Generalanother question Pin
ejtixo16-Dec-09 11:58
memberejtixo16-Dec-09 11:58 
Generalmy question Pin
ejtixo14-Dec-09 4:56
memberejtixo14-Dec-09 4:56 
GeneralRe: my question Pin
davidgiga15-Dec-09 3:13
memberdavidgiga15-Dec-09 3:13 
GeneralRe: my question [modified] Pin
ejtixo15-Dec-09 18:17
memberejtixo15-Dec-09 18:17 
GeneralMy vote of 2 Pin
davidgiga11-Dec-09 1:04
memberdavidgiga11-Dec-09 1:04 
NewsNew RS-Uploader Class [modified] Pin
davidgiga11-Dec-09 1:01
memberdavidgiga11-Dec-09 1:01 
Generalawsome coding Pin
Andy329-Oct-09 2:41
memberAndy329-Oct-09 2:41 
GeneralRe: awsome coding Pin
Michalss12-Oct-09 8:47
memberMichalss12-Oct-09 8:47 
GeneralMy request Pin
Softsiva31-Aug-09 22:10
memberSoftsiva31-Aug-09 22:10 
GeneralRe: My request Pin
kojoo8931-Aug-09 22:13
memberkojoo8931-Aug-09 22:13 Files don't work after Upload Pin
Bjoern M.20-Jul-09 12:02
memberBjoern M.20-Jul-09 12:02 
GeneralRe: .zip Files don't work after Upload Pin
Vitali Kaspler25-Jul-09 1:40
memberVitali Kaspler25-Jul-09 1:40 
GeneralRe: .zip Files don't work after Upload Pin
Bjoern M.25-Jul-09 3:05
memberBjoern M.25-Jul-09 3:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151002.1 | Last Updated 2 Apr 2009
Article Copyright 2009 by Ghasem Heyrani Nobari
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid