| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 454 人关注过本帖
标题:怎么写客户端显示服务器上rg文件中数据
只看楼主 加入收藏
qxm404499280
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-11-15
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:3 
怎么写客户端显示服务器上rg文件中数据
怎么写客户端客户端要现实服务器上rg文件中的数据
搜索更多相关主题的帖子: 客户端 服务器 客户端 服务器 
2012-11-15 15:45
mmxo
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:13
帖 子:189
专家分:1090
注 册:2012-11-7
收藏
得分:20 
WinForm? Silverlight?
最基本的是什么体系都不告诉,那就木有办法了,呵呵!

为提高中华编程水平而奋斗
2012-11-15 17:18
qxm404499280
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-11-15
收藏
得分:0 
回复 2楼 mmxo
winform
2012-11-19 13:01
mmxo
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:13
帖 子:189
专家分:1090
注 册:2012-11-7
收藏
得分:0 
这里给出一个例子,采用两种方式获取服务器上的文件数据:
1、WebClient直接下载数据或文件,这种方式要求你下载的文件必须是允许下载的(即服务器配置中你所访问的路径必须是被允许的),还有你访问的文件类型必须是已注册的(MIME类型);
2、Web服务方式,这要求你添加Web服务引用(是你自己写的网站就可以)或者添加该服务器上已存在且公开的相关Web服务;
3、代码只是示例如何获取文件,有些细节并未考虑,如数据长度、错误捕捉以及服务的访问许可等问题,请自行实现。

图片附件: 游客没有浏览图片的权限,请 登录注册


FormMain.cs
程序代码:
using System;
using using using using System.Text;
using System.Windows.Forms;

namespace ReadFileFromServer
{
    public partial class FormMain : Form
    {
        #region 全局字段

        private string _tempFile;

        #endregion

        #region 构造函数

        public FormMain()
        {
            InitializeComponent();
            RbAnonymous.CheckedChanged += RbAnonymous_CheckedChanged;
        }

        #endregion

        #region 控件事件

        private void ButGet_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(TbUri.Text)) return;
            var uri = new Uri(TbUri.Text);
            if (RbAnonymous.Checked)
            {
                if (RbGetData.Checked) GetDataWithAnonymous(uri);
                else GetFileWithAnonymous(uri);
            }
            else
                GetWithWebService(uri);
        }

        void RbAnonymous_CheckedChanged(object sender, EventArgs e)
        {
            GbGetMode.Enabled = RbAnonymous.Checked;
        }

        #endregion

        #region 事件处理

        void LzsdNet_GetFileCompleted(object sender, net.lzsd.www.GetFileCompletedEventArgs e)
        {
            TbResult.Text = Encoding.UTF8.GetString(e.Result);
            ButGet.Enabled = true;
        }

        void WebClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            var bytes = e.Result;
            TbResult.Text = Encoding.UTF8.GetString(bytes);
            ButGet.Enabled = true;
        }

        void WebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            ButGet.Enabled = true;
            TbResult.Text = File.ReadAllText(_tempFile);
            File.Delete(_tempFile);
        }

        #endregion

        #region 私有方法

        private void GetDataWithAnonymous(Uri uri)
        {
            var wc = new WebClient();
            wc.DownloadDataCompleted += WebClient_DownloadDataCompleted;
            ButGet.Enabled = false;
            wc.DownloadDataAsync(uri);
        }

        private void GetFileWithAnonymous(Uri uri)
        {
            var wc = new WebClient();
            wc.DownloadFileCompleted += WebClient_DownloadFileCompleted;
            _tempFile = Path.GetTempFileName();
            ButGet.Enabled = false;
            wc.DownloadFileAsync(uri, _tempFile);
        }

        private void GetWithWebService(Uri uri)
        {
            var lzsdNet = new net.lzsd.www.WSGetFile();
            lzsdNet.GetFileCompleted += LzsdNet_GetFileCompleted;
            lzsdNet.GetFileAsync(uri.Segments[uri.Segments.Length - 1]);
        }

        #endregion
    }
}


FormMain.Designer.cs
程序代码:
namespace ReadFileFromServer
{
    partial class FormMain
    {
        private  components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null)) components.Dispose();
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.TbUri = new System.Windows.Forms.TextBox();
            this.ButGet = new System.Windows.Forms.Button();
            this.TbResult = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.RbAnonymous = new System.Windows.Forms.RadioButton();
            this.RbWebService = new System.Windows.Forms.RadioButton();
            this.GbGetMode = new System.Windows.Forms.GroupBox();
            this.RbGetFile = new System.Windows.Forms.RadioButton();
            this.RbGetData = new System.Windows.Forms.RadioButton();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.GbGetMode.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.SuspendLayout();

            this.TbUri.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | 
                System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
            this.TbUri.Location = new System.Drawing.Point(43, 12);
            this.TbUri.Name = "TbUri";
            this.TbUri.Size = new System.Drawing.Size(211, 21);
            this.TbUri.TabIndex = 0;
            this.TbUri.Text = "http://www.";

            this.ButGet.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | 
                System.Windows.Forms.AnchorStyles.Right)));
            this.ButGet.Location = new System.Drawing.Point(260, 10);
            this.ButGet.Name = "ButGet";
            this.ButGet.Size = new System.Drawing.Size(75, 23);
            this.ButGet.TabIndex = 1;
            this.ButGet.Text = "获取(&B)";
            this.ButGet.UseVisualStyleBackColor = true;
            this.ButGet.Click += new System.EventHandler(this.ButGet_Click);

            this.TbResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | 
                System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | 
                System.Windows.Forms.AnchorStyles.Right)));
            this.TbResult.Location = new System.Drawing.Point(12, 143);
            this.TbResult.MaxLength = 32767000;
            this.TbResult.Multiline = true;
            this.TbResult.Name = "TbResult";
            this.TbResult.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.TbResult.Size = new System.Drawing.Size(323, 119);
            this.TbResult.TabIndex = 2;

            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 12);
            this.label1.TabIndex = 3;
            this.label1.Text = "Uri:";

            this.RbAnonymous.AutoSize = true;
            this.RbAnonymous.Checked = true;
            this.RbAnonymous.Location = new System.Drawing.Point(6, 22);
            this.RbAnonymous.Name = "RbAnonymous";
            this.RbAnonymous.Size = new System.Drawing.Size(71, 16);
            this.RbAnonymous.TabIndex = 4;
            this.RbAnonymous.TabStop = true;
            this.RbAnonymous.Text = "匿名方式";
            this.RbAnonymous.UseVisualStyleBackColor = true;

            this.RbWebService.AutoSize = true;
            this.RbWebService.Location = new System.Drawing.Point(83, 22);
            this.RbWebService.Name = "RbWebService";
            this.RbWebService.Size = new System.Drawing.Size(113, 16);
            this.RbWebService.TabIndex = 5;
            this.RbWebService.Text = "Web Service方式";
            this.RbWebService.UseVisualStyleBackColor = true;

            this.GbGetMode.Controls.Add(this.RbGetData);
            this.GbGetMode.Controls.Add(this.RbGetFile);
            this.GbGetMode.Location = new System.Drawing.Point(14, 91);
            this.GbGetMode.Name = "GbGetMode";
            this.GbGetMode.Size = new System.Drawing.Size(321, 46);
            this.GbGetMode.TabIndex = 6;
            this.GbGetMode.TabStop = false;
            this.GbGetMode.Text = "数据获取方式";

            this.RbGetFile.AutoSize = true;
            this.RbGetFile.Checked = true;
            this.RbGetFile.Location = new System.Drawing.Point(6, 20);
            this.RbGetFile.Name = "RbGetFile";
            this.RbGetFile.Size = new System.Drawing.Size(71, 16);
            this.RbGetFile.TabIndex = 5;
            this.RbGetFile.Text = "获取文件";
            this.RbGetFile.UseVisualStyleBackColor = true;

            this.RbGetData.AutoSize = true;
            this.RbGetData.Location = new System.Drawing.Point(83, 20);
            this.RbGetData.Name = "RbGetData";
            this.RbGetData.Size = new System.Drawing.Size(95, 16);
            this.RbGetData.TabIndex = 6;
            this.RbGetData.Text = "直接获取数据";
            this.RbGetData.UseVisualStyleBackColor = true;

            this.groupBox2.Controls.Add(this.RbAnonymous);
            this.groupBox2.Controls.Add(this.RbWebService);
            this.groupBox2.Location = new System.Drawing.Point(14, 39);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(321, 46);
            this.groupBox2.TabIndex = 7;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "访问类型";

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(347, 274);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.GbGetMode);
            this.Controls.Add(this.TbUri);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.TbResult);
            this.Controls.Add(this.ButGet);
            this.Name = "FormMain";
            this.ShowIcon = false;
            this.Text = "Read File From Server by ";
            this.GbGetMode.ResumeLayout(false);
            this.GbGetMode.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        private System.Windows.Forms.TextBox TbUri;
        private System.Windows.Forms.Button ButGet;
        private System.Windows.Forms.TextBox TbResult;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.RadioButton RbAnonymous;
        private System.Windows.Forms.RadioButton RbWebService;
        private System.Windows.Forms.GroupBox GbGetMode;
        private System.Windows.Forms.RadioButton RbGetData;
        private System.Windows.Forms.RadioButton RbGetFile;
        private System.Windows.Forms.GroupBox groupBox2;
    }
}


[ 本帖最后由 mmxo 于 2012-11-19 16:07 编辑 ]

为提高中华编程水平而奋斗
2012-11-19 16:06
快速回复:怎么写客户端显示服务器上rg文件中数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033055 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved