我该如何刷新我的网站?

I have in c# application that update a text file each few minutes with a different data inside.

For example first time in the text file there: Hello world After a minute the text file contain: Hi everyone

Now in the c# application i'm uploading the text file once it was change.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;

namespace ScrollLabelTest
{
    class FtpFileUploader
    {
        static string ftpurl = "ftp://ftp.test.com/files/theme/";
        static string filename = @"c:\temp\test.txt";
        static string ftpusername = "un";
        static string ftppassword = "ps";
        static string value;

        public static void test()
        {
            try
            {

                FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(
                ftpurl + "/" + Path.GetFileName(filename));
                request.Method = WebRequestMethods.Ftp.UploadFile;


                request.Credentials = new NetworkCredential(ftpusername, ftppassword);


                StreamReader sourceStream = new StreamReader(@"c:\temp\test.txt");
                byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();
                request.ContentLength = fileContents.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

                response.Close();
            }
            catch(Exception err)
            {
                string t = err.ToString();
            }
        }
    }
}

I see on my hard disk the text file is changed the content and also after uploading the file to my website ftp i see there the updated text file.

Now in my website i'm using javascript/ajax to read the uploaded text file:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://newsxpressmedia.com/files/theme/jquery.newsTicker.js"></script>

<div id="oneliner">
    <div class="header"> Breaking News </div>
    <ul class="newsticker">
<script>
$(function() {
    var file = "http://newsxpressmedia.com/files/theme/test.txt";
    $.get(file, function (txt) {
        //var lines = txt.responseText.split("
");
        var lines = txt.split("
");
        $ul = $('<ul class="newsticker" />');
        for (var i = 0, len = lines.length; i < len; i++) {
            //save(lines[i]); // not sure what this does
            $ul.append('<li>' + lines[i] + '</li>');
        }
        //$ul.appendTo('body').newsTicker({
        $ul.appendTo('div.wcustomhtml').newsTicker({
            row_height: 48,
            max_rows: 2,
            speed: 6000,
            direction: 'up',
            duration: 1000,
            autostart: 1,
            pauseOnHover: 1
        });
    });
});
</script>
</ul>
</div>

The problem is once my application in c# updated the file and uploaded it to the ftp i need in my browser for example chrome to make manual refresh if not it will keep showing the old text file content and not the updated.

How can i make a refresh maybe in the javascript ?

Try like this

No need to refresh the page just refresh the function that will get the latest info from text file

$(function() {
    news();
    setInterval(function(){
      news()
    },60000)  // it will call every 1 min you can change it
});

function news(){
   $('body').find('.newsticker').remove();//It will clear old data if its present 
   var file = "http://newsxpressmedia.com/files/theme/test.txt";
    $.get(file, function (txt) {
        //var lines = txt.responseText.split("
");
        var lines = txt.split("
");
        $ul = $('<ul class="newsticker" />');
        for (var i = 0, len = lines.length; i < len; i++) {
            //save(lines[i]); // not sure what this does
            $ul.append('<li>' + lines[i] + '</li>'); //here 
        }
        //$ul.appendTo('body').newsTicker({
        $ul.appendTo('div.wcustomhtml').newsTicker({
            row_height: 48,
            max_rows: 2,
            speed: 6000,
            direction: 'up',
            duration: 1000,
            autostart: 1,
            pauseOnHover: 1
        });
    });
}

If you want to refresh the page every minute from JavaScript then

setInterval(function () {
    //retrieve file from server and update html with new contents
}, 60000)

will do the trick. However, using this approach will reload the file every minute, even if the file hasn't actually been changed.

You could look into SignalR to trigger everything from the server side. What you would do is create a hub which, once a new version of the file has been uploaded, will send a notification to all subscribed clients (one of which will be your website). This will ensure that the page gets updated only when the file actually changes.

You can read more about SignalR here.

Simply use asp:timer control and puts your content in UpdatePanel that's it.

you can also see example for timer and set time as per your time requirement.

http://msdn.microsoft.com/en-us/library/bb398865(v=vs.100).aspx

Using javascript:

setTimeout(function() {
    location.reload();
}, 300000);