Matt9892's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
5 (0.01 per day)
Joined:
14-February 12
Profile Views:
57
Last Active:
User is offline Apr 14 2012 03:49 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Matt9892 has not set their status

Posts I've Made

  1. In Topic: .Uploadstring class help.. overwriting a txt files data thats online

    Posted 13 Apr 2012

    I understand what you are saying but i cant really post any code for that because i dont have any.. Thats the problem.. i have been trying various methoeds.. i cant get any to work.
    At this time i am trying
            public string[] readdata()
            {
                WebClient wc = new WebClient();
                string dwnld = wc.DownloadString("http://mbtesting.webs.com/Data.txt");
                string after = dwnld.Replace("\r\n", ".");
                string[] split = after.Split('.');
                split = removelast(split);
                return split;
            }
                    WebClient wc = new WebClient();
                    string[] all = readdata();
                    string names = all[0] + textBox1.Text + ",";
                    string Lumberjacks = all[1] + numericUpDown1.Value.ToString() + ",";
                    string Trapper = all[2] + numericUpDown2.Value.ToString() + ",";
                    string Herbalist = all[3] + numericUpDown3.Value.ToString() + ",";
                    string Fisherman = all[4] + numericUpDown4.Value.ToString() + ",";
                    string Farmer = all[5] + numericUpDown5.Value.ToString() + ",";
                    string Miner = all[6] + numericUpDown6.Value.ToString() + ",";
                    string CCWeaponMaster = all[7] + numericUpDown7.Value.ToString() + ",";
                    string Armorer = all[8] + numericUpDown8.Value.ToString() + ",";
                    string LeatherDealer = all[9] + numericUpDown9.Value.ToString() + ",";
                    string LDWeaponMaster = all[10] + numericUpDown10.Value.ToString() + ",";
                    string Jeweler = all[11] + numericUpDown11.Value.ToString() + ",";
                    string Handyman = all[12] + numericUpDown12.Value.ToString() + ",";
                    string Baker = all[13] + numericUpDown13.Value.ToString() + ",";
                    string AOEWeaponMaster = all[14] + numericUpDown14.Value.ToString() + ",";
                    string Chef = all[15] + numericUpDown15.Value.ToString() + ",";
                    string Tailor = all[16] + numericUpDown16.Value.ToString() + ",";
                    string comb = combinestring(names, Lumberjacks, Trapper, Herbalist, Fisherman, Farmer, Miner, CCWeaponMaster, Armorer, LeatherDealer, LDWeaponMaster, Jeweler, Handyman, Baker, AOEWeaponMaster, Chef, Tailor);
                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    Byte[] bytes = encoding.GetBytes(comb);
                    wc.Credentials = new NetworkCredential("Username", "Password");
                    wc.UploadFile("http://mbtesting.webs.com/Data.txt", "PUT", ".//Data.txt");
                    wc.Dispose();
    
    

    If anyone could help its beginning to get to me have tried loads of diff methods. I am sure that some of you have a webs.com free website.. or even try to upload to mine :-p i dont mind.. i just need to know how to upload to it.. i dont mind if like the above i try to upload a whole file that i create or if i just try to upload the data from a file. I just cant seem to get anything to work. Or if anyone know of a free hosting service that i can (you have already) uploaded to using c# i would go to that..
    thanks in advance.

    I just need to read from the txt file at "http://mbtesting.webs.com/Data.txt" (which i have done) but after i make the changes (this one adds an entry) i need to replace the file at http://mbtesting.webs.com/Data.txt with the new one. Oh i know before you say anything that this version doesnt save any data back to a file i know that i changed the file myself (the old version)
                    string[] comb = combinestring(names1, Lumberjacks1, Trapper1, Herbalist1, Fisherman1, Farmer1, Miner1, CCWeaponMaster1, Armorer1, LeatherDealer1, LDWeaponMaster1, Jeweler1, Handyman1, Baker1, AOEWeaponMaster1, Chef1, Tailor1);
                    File.WriteAllLines(".//Data.txt", comb);
    
    

    writes all the data to a file.. so i just copied this over to the folder to test with.. but it doesnt upload it.

    Any help would be great, if you need to know anything else please ask.
    thanks
    Matt
    Matt
  2. In Topic: .Uploadstring class help.. overwriting a txt files data thats online

    Posted 12 Apr 2012

    ok.. let me try to explain.. i use seperate lines to work out what needs to go into the specific places on the form..
     
            public string[] readdata()
            {
                WebClient wc = new WebClient();
                string dwnld = wc.DownloadString("http://mbtesting.webs.com/Data.txt");
                string after = dwnld.Replace("\r\n", ".");
                string[] split = after.Split('.');
                split = removelast(split);
                return split;
            }
            string[] removelast(string[] pe)
            {
                List<string> buffer = new List<string>();
                buffer.Clear();
                int ab = pe.Length;
                for (int i = 0; i < ab; i++)
                {
                    if (i == ab - 1)
                    {
                    }
                    else
                    {
                        buffer.Add(pe[i]);
                    }
                }
                string[] buffer1 = buffer.ToArray();
                return buffer1;
            }
    
    

    so i read the txt file from this website (i have name and password, dunno if and where that needs to go) i split it into different arryas for different lines of the file.. then display and edit these as needed..
    then once i have edited.. if deleted ect i have turned them back into a string(was using arrays to write to the file when it was on my hd) the string i produce looks the same as the string that i get to start with i just need to upload/overwrite the txt file that exists already when an item gets added/deleted or added. i just have no idea how to write back to the file.. i used downloadstring to read so figured i would use upload to write.. but cant seem to get it working.
    if you need more info i could post my program that works (offline version) if you wish.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Matt9892 hasn't added any friends yet.

Comments

Matt9892 has no profile comments yet. Why not say hello?