首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 未能找到路径“E:\html\gg.html”的一部分。解决办法

2012-05-22 
C#未能找到路径“E:\html\gg.html”的一部分。C# codeusing Systemusing System.Collections.Genericusing

C# 未能找到路径“E:\html\gg.html”的一部分。

C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;//streamnamespace test11{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();            try            {                StreamWriter outStream = new StreamWriter("E://html//gg.html", false, Encoding.GetEncoding("GB2312"));            }            catch (IOException e)            {                System.Console.WriteLine("错误:" + e);            }        }    }}/*在 System.IO.DirectoryNotFoundException 中第一次偶然出现的“mscorlib.dll”类型的异常错误:System.IO.DirectoryNotFoundException: 未能找到路径“E:\html\gg.html”的一部分。   在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)   在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)   在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)   在 System.IO.StreamWriter.CreateFile(String path, Boolean append)   在 System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)   在 System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding)*/前几天还好好的,昨天就出现这样的问题了,求助大神,毕业设计问题


[解决办法]
试了一下代码,没问题的。估计是路径不对,有没有把html文件夹删掉啊
[解决办法]
操作文件先File.Exists(path)看文件是否存在;
----------------------------------
回10L
/// <summary>
/// 创建文件夹
/// </summary>
/// <param name="folderPath">文件夹地址</param>
public static void CreatFolder(string folderPath)
{
if (!Directory.Exists(folderPath))//如果不存在就创建file文件夹 
Directory.CreateDirectory(folderPath);//创建该文件夹
}
[解决办法]
我感觉应该这样吧:
if(!file.exit())
if(!directory.exit()){
directory.create();
file.create();
}
路径和文件都需要创建

探讨

如果我想要的是 给定一个带有目录和子目录的文件,如何在不存在目录的时候主动创建目录然后创建文件?
怎么实现? file.create? 还是必须先Directory.Create()?

[解决办法]
文件夹html还存在吗

DirectoryNotFoundException 

是文件夹没找到

热点排行