宁可辛苦一阵子,不要辛苦一辈子

VocanoLee学习手札

  博客园 :: 首页 :: 联系 :: 订阅 订阅 :: 管理
  22 Posts :: 0 Stories :: 18 Comments :: 0 Trackbacks

公告

2010年2月10日 #

本以为搭建VPN很麻烦,而且繁琐,亲身经历了一下后感觉不是很难!简单说下过程

1:关闭防火墙

2:启动Remote Procedure Call (RPC)服务

3:(管理工具中)配置路由和远程访问 选择自定义配置,后选择VPN访问

4:安装微软网络客户端(连接属性中)

5:启动Telephony 服务

6:启动Remote Access Connection Manager服务

7:启动Routing and Remote Access服务

8:然后添加NAT协议NAT/基本防火墙(IP/路由选择常规中添加)

9:添加内部接口 在CMD下依次执行:

netsh

routing

ip

nat

add interface 内部 private

到此全部搭建完成

posted @ 2010-02-10 03:15 VocanoLee 阅读(250) 评论(1) 编辑

2009年5月16日 #

using System;

using System.Collections.Generic;

using System.Text;

using System.Net;

using System.IO;

using System.Windows.Forms;

 

namespace ConvertData

{

    class FtpUpDown

    {

        string ftpServerIP;

        string ftpUserID;

        string ftpPassword;

        FtpWebRequest reqFTP;

        private void Connect(String path)//连接ftp

        {

            // 根据uri创建FtpWebRequest对象

            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));

            // 指定数据传输类型

            reqFTP.UseBinary = true;

            // ftp用户名和密码

            reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

        }

        public FtpUpDown(string ftpServerIP, string ftpUserID, string ftpPassword)

        {
            this.ftpServerIP = ftpServerIP;

            this.ftpUserID = ftpUserID;

            this.ftpPassword = ftpPassword;
        }

        //都调用这个

        private string[] GetFileList(string path, string WRMethods)//上面的代码示例了如何从ftp服务器上获得文件列表

        {
            string[] downloadFiles;
            StringBuilder result = new StringBuilder();
            try

            {
                Connect(path);

                reqFTP.Method = WRMethods;

                WebResponse response = reqFTP.GetResponse();

                StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);//中文文件名

                string line = reader.ReadLine();

                while (line != null)

                {

                    result.Append(line);

                    result.Append("\n");

                    line = reader.ReadLine();

                }

                // to remove the trailing '\n'

                result.Remove(result.ToString().LastIndexOf('\n'), 1);

                reader.Close();

                response.Close();

                return result.ToString().Split('\n');

            }

            catch (Exception ex)

            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

                downloadFiles = null;

                return downloadFiles;
            }
        }

        public string[] GetFileList(string path)//上面的代码示例了如何从ftp服务器上获得文件列表

        {
            return GetFileList("ftp://" + ftpServerIP + "/" + path, WebRequestMethods.Ftp.ListDirectory);
        }
        public string[] GetFileList()//上面的代码示例了如何从ftp服务器上获得文件列表

        {
            return GetFileList("ftp://" + ftpServerIP + "/", WebRequestMethods.Ftp.ListDirectory);
        }

        public void Upload(string filename) //上面的代码实现了从ftp服务器上载文件的功能

        {
            FileInfo fileInf = new FileInfo(filename);

            string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;

            Connect(uri);//连接         

            // 默认为true,连接不会被关闭

            // 在一个命令之后被执行

            reqFTP.KeepAlive = false;

            // 指定执行什么命令

            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

            // 上传文件时通知服务器文件的大小

            reqFTP.ContentLength = fileInf.Length;
            // 缓冲大小设置为kb
            int buffLength = 2048;
            byte[] buff = new byte[buffLength];

            int contentLen;

            // 打开一个文件流(System.IO.FileStream) 去读上传的文件

            FileStream fs = fileInf.OpenRead();

            try

            {

                // 把上传的文件写入流

                Stream strm = reqFTP.GetRequestStream();

                // 每次读文件流的kb

                contentLen = fs.Read(buff, 0, buffLength);

                // 流内容没有结束

                while (contentLen != 0)

                {
                    // 把内容从file stream 写入upload stream
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);

                }

                // 关闭两个流

                strm.Close();

                fs.Close();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message, "Upload Error");

            }

        }

        public bool Download(string filePath, string fileName, out string errorinfo)////上面的代码实现了从ftp服务器下载文件的功能

        {
            try

            {
                String onlyFileName = Path.GetFileName(fileName);

                string newFileName = filePath + "\\" + onlyFileName;

                if (File.Exists(newFileName))

                {

                    errorinfo = string.Format("本地文件{0}已存在,无法下载", newFileName);
                    return false;
                }
                string url = "ftp://" + ftpServerIP + "/" + fileName;
                Connect(url);//连接 
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                long cl = response.ContentLength;
                int bufferSize = 2048;
                int readCount;
                byte[] buffer = new byte[bufferSize];
                readCount = ftpStream.Read(buffer, 0, bufferSize);

                FileStream outputStream = new FileStream(newFileName, FileMode.Create);
                while (readCount > 0)

                {
                    outputStream.Write(buffer, 0, readCount);
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                }
                ftpStream.Close();
                outputStream.Close();
                response.Close();

                errorinfo = "";

                return true;

            }

            catch (Exception ex)

            {
                errorinfo = string.Format("因{0},无法下载", ex.Message);

                return false;

            }

        }

        //删除文件

        public void DeleteFileName(string fileName)

        {
            try

            {
                FileInfo fileInf = new FileInfo(fileName);

                string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;

                Connect(uri);//连接         

                // 默认为true,连接不会被关闭

                // 在一个命令之后被执行

                reqFTP.KeepAlive = false;

                // 指定执行什么命令

                reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;

                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                response.Close();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message, "删除错误");

            }

        }

        //创建目录

        public void MakeDir(string dirName)

        {
            try

            {
                string uri = "ftp://" + ftpServerIP + "/" + dirName;

                Connect(uri);//连接      

                reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;

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

                response.Close();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

        //删除目录

        public void delDir(string dirName)

        {
            try

            {
                string uri = "ftp://" + ftpServerIP + "/" + dirName;

                Connect(uri);//连接      

                reqFTP.Method = WebRequestMethods.Ftp.RemoveDirectory;

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

                response.Close();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

        //获得文件大小

        public long GetFileSize(string filename)

        {

 

            long fileSize = 0;

            try

            {

                FileInfo fileInf = new FileInfo(filename);

                string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;

                Connect(uri);//连接      

                reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;

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

                fileSize = response.ContentLength;

                response.Close();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

            return fileSize;

        }

        //文件改名

        public void Rename(string currentFilename, string newFilename)

        {
            try

            {
                FileInfo fileInf = new FileInfo(currentFilename);

                string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;

                Connect(uri);//连接

                reqFTP.Method = WebRequestMethods.Ftp.Rename;

                reqFTP.RenameTo = newFilename;

 

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

                //Stream ftpStream = response.GetResponseStream();

                //ftpStream.Close();

                response.Close();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

        //获得文件明晰

        public string[] GetFilesDetailList()

        {

            return GetFileList("ftp://" + ftpServerIP + "/", WebRequestMethods.Ftp.ListDirectoryDetails);

        }

        //获得文件明晰

        public string[] GetFilesDetailList(string path)

        {

            return GetFileList("ftp://" + ftpServerIP + "/" + path, WebRequestMethods.Ftp.ListDirectoryDetails);

        }

    }
}

 

测试

       //获得文件列表

       private void button1_Click(object sender, EventArgs e)

        {

            FtpUpDown ftpUpDown = new FtpUpDown(ConvertData.Properties.Settings.Default.ftpServerIP, ConvertData.Properties.Settings.Default.ftpUserID, ConvertData.Properties.Settings.Default.ftpPassword);

            string[] str = ftpUpDown.GetFileList("2005");

            richTextBox1.Lines = str;

        }

        //下载

        private void button2_Click(object sender, EventArgs e)

        {

            FtpUpDown ftpUpDown = new FtpUpDown(ConvertData.Properties.Settings.Default.ftpServerIP, ConvertData.Properties.Settings.Default.ftpUserID, ConvertData.Properties.Settings.Default.ftpPassword);

            ftpUpDown.Download("c:\\", "2007/11/01/57070.pdf");

        }

        //上传

        private void button3_Click(object sender, EventArgs e)

        {

            FtpUpDown ftpUpDown = new FtpUpDown(ConvertData.Properties.Settings.Default.ftpServerIP, ConvertData.Properties.Settings.Default.ftpUserID, ConvertData.Properties.Settings.Default.ftpPassword);

            ftpUpDown.Upload("c:\\57070.pdf");

        }

posted @ 2009-05-16 02:51 VocanoLee 阅读(274) 评论(0) 编辑

2009年5月15日 #

关于.Net 调试 运行的时候,页面无法显示的解决方法

 

 

现在我把解决方法说下,希望有朋友和我一样的就不用走弯路了~~ 你可以看一下你装的杀软是什么,一般就是杀软的问题。

我用的杀软是NOD32的。所以我是这么解决的。

用ie调试的时候发现:IE地址栏里面显示端口号和桌面任务栏右下角“ASP.NET Development Server”的端口压根就不一致(通常就相差个位数),我把IE地址栏的端口号改成“ASP.NET Development Server”显示的端口号,结果网页就出来了,原来是nod32(NOD32 3.0以上版本)的缘故(08下用这个防火墙的人应该蛮多的,所以把帖子发到这里),
解决办法:
    进入NOD32的高级设置(F5),Web访问保护,HTTP,Web浏览器,会看到一个程序列表你的devenv.exe应该在其中,双击前面的勾(相当于去掉选中状态),确定退出。重新打开vs再调试一下,问题解决。

就应该是端口号和ASP.NET Development Server 运行起来的口号不对应,改过来就可以了。

 

希望有帮助~~

posted @ 2009-05-15 22:00 VocanoLee 阅读(295) 评论(3) 编辑

2009年5月6日 #

  string keyName;
            string keyValue;

            keyName = "MyApp";
            keyValue = "My Application";

            RegistryKey key;
            key = Registry.ClassesRoot.CreateSubKey(keyName);
            key.SetValue("", keyValue);
            key = key.CreateSubKey("shell");
            key = key.CreateSubKey("open");
            key = key.CreateSubKey("command");
            key.SetValue("", @"C:\app.exe");

            keyName = ".bbb"; //相应后缀
            keyValue = "MyApp";
            key = Registry.ClassesRoot.CreateSubKey(keyName);
            key.SetValue("", keyValue);

posted @ 2009-05-06 12:59 VocanoLee 阅读(137) 评论(0) 编辑

  1 using System;

    2 using System.Collections.Generic;

    3 using System.ComponentModel;

    4 using System.Data;

    5 using System.Drawing;

    6 using System.Text;

    7 using System.Windows.Forms;

    8 using System.Runtime.InteropServices;  //名字空间

    9 

   10 namespace CS_ListViewAddFileIco

   11 {

   12     public partial class Form1 : Form

   13     {

   14         private int i;

   15         public Form1()

   16         {

   17             InitializeComponent();

   18             i = 0;

   19         }

   20 

   21         [DllImport("Shell32.dll")]

   22         private static extern int SHGetFileInfo

   23         (

   24         string pszPath,

   25         uint dwFileAttributes,

   26         out   SHFILEINFO psfi,

   27         uint cbfileInfo,

   28         SHGFI uFlags

   29         );

   30         [StructLayout(LayoutKind.Sequential)]

   31         private struct SHFILEINFO

   32         {

   33             public SHFILEINFO(bool b)

   34             {

   35                 hIcon = IntPtr.Zero; iIcon = 0; dwAttributes = 0; szDisplayName = ""; szTypeName = "";

   36             }

   37             public IntPtr hIcon;

   38             public int iIcon;

   39             public uint dwAttributes;

   40             [MarshalAs(UnmanagedType.LPStr, SizeConst = 260)]

   41             public string szDisplayName;

   42             [MarshalAs(UnmanagedType.LPStr, SizeConst = 80)]

   43             public string szTypeName;

   44         };

   45         private enum SHGFI

   46         {

   47             SmallIcon = 0x00000001,

   48             LargeIcon = 0x00000000,

   49             Icon = 0x00000100,

   50             DisplayName = 0x00000200,

   51             Typename = 0x00000400,

   52             SysIconIndex = 0x00004000,

   53             UseFileAttributes = 0x00000010

   54         }

   55         public static Icon GetFileIcon(string fileName, bool largeIcon)

   56         {

   57             SHFILEINFO info = new SHFILEINFO(true);

   58             int cbFileInfo = Marshal.SizeOf(info);

   59             SHGFI flags;

   60             if (largeIcon)

   61                 flags = SHGFI.Icon | SHGFI.LargeIcon | SHGFI.UseFileAttributes;

   62             else

   63                 flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes;

   64             SHGetFileInfo(fileName, 256, out info, (uint)cbFileInfo, flags);

   65             return Icon.FromHandle(info.hIcon);

   66         }

   67         private void btnAdd_Click(object sender, EventArgs e)

   68         {

   69             Icon ico = GetFileIcon(tbFileName.Text, true);

   70             imageList1.Images.Add(ico);

   71             listView1.LargeImageList = imageList1;

   72             listView1.Items.Add(tbFileName.Text, i++);

   73 

   74         }

   75     }

   76 }

posted @ 2009-05-06 12:58 VocanoLee 阅读(195) 评论(0) 编辑

2009年4月8日 #

/// <summary>
        
/// ftp的上传功能
        
/// </summary>
        
/// <param name="ftpServerIP"></param>
        
/// <param name="filename"></param>
        
/// <param name="ftpUserID"></param>
        
/// <param name="ftpPassword"></param>
        public static void Upload(string ftpServerIP, string filename, string ftpUserID, string ftpPassword)
        {
            FileInfo fileInf 
= new FileInfo(filename);

            
string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
            FtpWebRequest reqFTP;

            
// 根据uri创建FtpWebRequest对象 
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileInf.Name));

            
// ftp用户名和密码
            reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

            
// 默认为true,连接不会被关闭
            
// 在一个命令之后被执行
            reqFTP.KeepAlive = false;

            
// 指定执行什么命令
            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

            
// 指定数据传输类型
            reqFTP.UseBinary = true;

            
// 上传文件时通知服务器文件的大小
            reqFTP.ContentLength = fileInf.Length;

            
// 缓冲大小设置为2kb
            int buffLength = 2048;

            
byte[] buff = new byte[buffLength];
            
int contentLen;

            
// 打开一个文件流 (System.IO.FileStream) 去读上传的文件
            FileStream fs = fileInf.OpenRead();
            
try
            {
                
// 把上传的文件写入流
                Stream strm = reqFTP.GetRequestStream();

                
// 每次读文件流的2kb
                contentLen = fs.Read(buff, 0, buffLength);

                
// 流内容没有结束
                while (contentLen != 0)
                {
                    
// 把内容从file stream 写入 upload stream
                    strm.Write(buff, 0, contentLen);

                    contentLen 
= fs.Read(buff, 0, buffLength);
                }

                
// 关闭两个流
                strm.Close();
                fs.Close();
            }
            
catch (Exception ex)
            {
                
// MessageBox.Show(ex.Message, "Upload Error");
                HttpContext.Current.Response.Write("Upload Error:" + ex.Message);
            }
        }

posted @ 2009-04-08 04:39 VocanoLee 阅读(278) 评论(0) 编辑

2009年3月20日 #

摘要: Flex Builder 3.0 For Eclipse 3.3 安装方法转自http://blog.csdn.net/surpaimb/archive/2008/04/08/2264171.aspx[quote]这两天准备学习Flex,于是下载了Flex Builder 3.0 For Eclipse plugin准备安装.但是安装后启动Eclipse,找了半天也没找到Flex.而且Flex B...阅读全文
posted @ 2009-03-20 02:13 VocanoLee 阅读(1635) 评论(0) 编辑

2008年11月24日 #

摘要: 透过IL看C# (外一篇)警惕常量陷阱原文地址:http://www.cnblogs.com/AndersLiu/archive/2008/11/23/csharp-via-il-constant-a.html原创:Anders Liu摘要:常量的含义本是“永远不会变的量”,但是如果作为类库开发人员,把常量用作“可以由我变,但不能由你变”的量,那就可...阅读全文
posted @ 2008-11-24 11:04 VocanoLee 阅读(54) 评论(0) 编辑

2008年10月30日 #

摘要: 方法参数上的 out 方法参数关键字使方法引用传递到方法的同一个变量。当控制传递回调用方法时,在方法中对参数所做的任何更改都将反映在该变量中。 当希望方法返回多个值时,声明 out 方法非常有用。使用 out 参数的方法仍然可以返回一个值。一个方法可以有一个以上的 out 参数。 若要使用 out 参数,必须将参数作为 out 参数显式传递到方法。out 参数的值不会传递到 out 参数。 不必初...阅读全文
posted @ 2008-10-30 14:41 VocanoLee 阅读(127) 评论(0) 编辑

2008年10月10日 #

摘要: 无法显示 XML 页。 使用 XSL 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。 --------------------------------------------------------------------------------名称以无效字符开头。处理资源 'http://localhost/Asp.net/Default.aspx' 时出错。第 1 行...阅读全文
posted @ 2008-10-10 13:28 VocanoLee 阅读(732) 评论(0) 编辑