7 Replies - 1510 Views - Last Post: 02 June 2013 - 01:21 PM Rate Topic: -----

#1 techcomputerman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 29-May 13

saving listbox online to a server

Posted 02 June 2013 - 11:43 AM

Hi guys, I have a textfile online that connects to my app and is fully readable/writeable. To read the file, i just code the following
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://mysite.com/myfolder/file.txt")
Dim response As System.Net.HttpWebResponse = request.GetResponse
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream)

ListBox1.Items.Add(sr.ReadLine)
Label7.text=ListBox1.selectedindex=0
ListBox1.Items.Remove(Listbox1.selectedItem)


So i want to save these changes to the textfile (removing stuff on the listbox). How would i do that??

Is This A Good Question/Topic? 0
  • +

Replies To: saving listbox online to a server

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,483
  • Joined: 12-December 12

Re: saving listbox online to a server

Posted 02 June 2013 - 12:24 PM

Someone may correct me, but your website needs to be ftp-enabled. This might give you a domain like ftp.mysite.com. Users who can upload files will also need to be given credentials (username and password).

How to Upload files with FTP

The file could be saved and stored in the (local) temp folder, before being uploaded.

However, I don't know what happens to the file after it is uploaded? I suppose it would require a server-side script (maybe a cron job) to move the file, so that it replaces the original. (I don't know if this could happen automatically with server-side settings?).

Alternatively, this can be done via a web-page, using an HTML-form and requiring a server-side script to process the upload.
Was This Post Helpful? 0
  • +
  • -

#3 techcomputerman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 29-May 13

Re: saving listbox online to a server

Posted 02 June 2013 - 12:27 PM

I have a PHP saving script but how would i code it for the streamwriter to write for http://mysite.com/mi...les/post.php?w= (the PHP will automaticly resave the txt file)
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13965
  • View blog
  • Posts: 55,749
  • Joined: 12-June 08

Re: saving listbox online to a server

Posted 02 June 2013 - 12:53 PM

You wouldn't use stream writer.. at best *maybe* file writer, but your best shot is either a webservice to write the file, ftp as andre mentioned, or put the file in a database and use a webservice.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,483
  • Joined: 12-December 12

Re: saving listbox online to a server

Posted 02 June 2013 - 01:03 PM

View Posttechcomputerman, on 02 June 2013 - 07:27 PM, said:

I have a PHP saving script but how would i code it for the streamwriter to write for http://mysite.com/mi...les/post.php?w= (the PHP will automaticly resave the txt file)

If your PHP script processes a file uploaded via an HTML-form then I don't believe it is possible to automate this process (someone might dispute this!). It is not possible using an Ajax request, although it is, I understand, now possible to do this in modern browsers using XHR2 and the FormData object.

https://developer.mo...ormData_Objects

Added: Well, it is kind-of possible to do this with Ajax (before XHR2) using a hidden iframe but, to me, this is not the same as a simple file upload :)

This post has been edited by andrewsw: 02 June 2013 - 01:07 PM

Was This Post Helpful? 0
  • +
  • -

#6 techcomputerman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 29-May 13

Re: saving listbox online to a server

Posted 02 June 2013 - 01:06 PM

well my script lets me save any file...done it before...but all i want to know is the code were i can tell it to webrequest my php file and get webresponse
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13965
  • View blog
  • Posts: 55,749
  • Joined: 12-June 08

Re: saving listbox online to a server

Posted 02 June 2013 - 01:14 PM

Here's a tutorial for snapping together a php webservice and vb.net... you might get a good direction from that.

http://www.dreaminco...sumed-by-vbnet/
Was This Post Helpful? 0
  • +
  • -

#8 techcomputerman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 29-May 13

Re: saving listbox online to a server

Posted 02 June 2013 - 01:21 PM

Here's the code i want...instead of savedialog, i want to put request.GetResponse
so lets say request is:
Dim request As WebRequest = WebRequest.Create("http://mysite.com/post.php?w=")



 If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                Dim count As Integer = -1
                Dim writer As New IO.StreamWriter(SaveFileDialog1.FileName)
                Dim current As Integer = ListBox1.SelectedIndex
                Try
                    Do Until count = ListBox1.Items.Count
                        ListBox1.SelectedIndex = count + 1
                        writer.WriteLine(ListBox1.SelectedItem)
                        count = count + 1

                    Loop
                Catch ex As Exception
                    writer.Close()
                    ListBox1.SelectedIndex = current

                End Try

            Catch ex As Exception

            End Try
        End If


how can i get rid of savedialog and put request.GetResponse....because i dont know how...ik it will work because i done this code with other objects but i need to use the exact or similer listbox code as i used for the savedialog
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1