分享

写回答

发帖

[介绍] GoDaddy美国主机支持FSO生成页面

GoDaddy GoDaddy 1477 人阅读 | 0 人回复

发表于 2011-3-14 11:25:33 | 显示全部楼层 |阅读模式

如题, GoDaddy Windows主机是支持FSO生成页面, FSO组件全称为:FileSystemObject
GoDaddy支持的组件一览表地址:http://help.godaddy.com/article/1584

有朋友FSO的时候出现错误,一般由如下原因造成:
  • 没设置读写权限
  • 写路径不对


设置读写权限参考:GoDaddy主机设置读写权限教程
路径问题,可能需要简单修改一下代码
比如关于新云cms的:GoDaddy主机新云cms生成html静态页面为0的解决方法
比如下面这个实例代码是错误的:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.IO;
  8. using System.Text;
  9. using System.Security.Permissions;


  10. public partial class cvInserting : System.Web.UI.Page
  11. {
  12.     protected void Page_Load(object sender, EventArgs e)
  13.     {

  14.     }

  15.    

  16.     public class test
  17.     {
  18.         public static void Main()
  19.         {
  20.             string path = @"C:\TestFile.Txt";

  21.             try
  22.             {
  23.                 using (FileStream fs = File.Create(path))
  24.                 {
  25.                     byte[] info = new UTF8Encoding(true).GetBytes("this is a test.");
  26.                     fs.Write(info, 0, info.Length);
  27.                 }

  28.                 using (StreamReader sr = File.OpenText(path))
  29.                 {
  30.                     string s = "this is a test";
  31.                     while ((s = sr.ReadLine()) != null)
  32.                     {
  33.                         Console.WriteLine(s);
  34.                     }
  35.                 }

  36.             }

  37.             catch (Exception Ex)
  38.             {
  39.                 Console.WriteLine(Ex.ToString());
  40.             }
  41.         }
  42.    
  43.     }

  44. }
复制代码
改为如下代码则运行的非常好:
  1. using System;
  2. using System.IO;
  3. using System.Text;

  4. public partial class cvInserting : System.Web.UI.Page
  5. {
  6.     protected void Page_Load(object sender, EventArgs e)
  7.     {
  8.         // The path to file in the data directory.
  9.         // Data directory must have a write access enabled
  10.         string path = Server.MapPath("/TestFile.Txt");


  11.         using (FileStream fs = File.Create(path))
  12.         {
  13.             byte[] info = new UTF8Encoding(true).GetBytes("this is a test.");
  14.             fs.Write(info, 0, info.Length);
  15.         }

  16.         using (StreamReader sr = File.OpenText(path))
  17.         {
  18.             string s;
  19.             while ((s = sr.ReadLine()) != null)
  20.             {
  21.                 Response.Write(s);
  22.             }
  23.         }
  24.     }
  25. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则