基本上我只想将Gziped文件加载到富文本框中。我在MS .NET站点上找到了一些用于解压文件的代码。现在我想将该流指向一个富文本框,但我不断收到错误“非静态字段,方法或属性需要对象引用''WindowsFormsApplication1.Form1.richTextBox1''尝试从Gzip解压缩过程将文件流加载到RichTextBox时出现非静态错误
代码是这里。我究竟做错了什么?提前致谢。
public static void Decompress(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Get original file extension, for example
// "doc" from report.doc.gz.
string curFile = fi.FullName;
string origName = curFile.Remove(curFile.Length -
fi.Extension.Length);
//Create the decompressed file.
using (FileStream outFile = File.Create(origName))
{
using (GZipStream Decompress = new GZipStream(inFile,
CompressionMode.Decompress))
{
// Copy the decompression stream
// into the output file.
Decompress.CopyTo(outFile);
richTextBox1.LoadFile(Decompress.CopyTo(outFile), RichTextBoxStreamType.PlainText);
// problem right here ^^^^
}//using
}//using
}//using
}//DeCompress
你是对的。但是,这会产生与OP提到的不同的编译器错误。这没有意义。也许他只是贴错了一个。 –
@Charles你是对的。他解除的例子是一种静态方法。 “这里的问题^^^^”指的是错误的问题。 – LarsTech