S
shapper
Hello,
I am trying to implement a new class based on
System.Web.HttpPostedFileBase so I can create a two directional
mapping between byte[] File and HttpPostedFileBase. So I have the
following:
public class HttpFile : HttpPostedFileBase, IDisposable {
public override int ContentLength { get { return (int)
this.InputStream.Length; } }
public override string ContentType { get { return
this._ContentType; } set { _ContentType = value; } }
private string _ContentType;
public override string FileName { get { return base.FileName; }
set { _FileName = value; } }
private string _FileName;
public override Stream InputStream {
get {
if (_Stream == null) {
_Stream = new FileStream(_FileName, FileMode.Open,
FileAccess.Read, FileShare.Read);
}
return _Stream;
}
}
private FileStream _Stream;
public HttpFile(string fileName, string contentType) {
this._ContentType = contentType;
this._FileName = fileName;
} // HttpFile
public void Dispose() {
if (_Stream != null) {
try { _Stream.Dispose(); } finally { _Stream = null; }
}
} // Dispose
public override void SaveAs(String filename) {
File.WriteAllBytes(filename, File.ReadAllBytes(_FileName));
} // SaveAs
}
I need to be able to create an HttpFile where its stream is taken from
a byte[] object.
How can I do this?
I am a little bit confused about this.
Note: in ContentType and FileName properties I added the "set" code.
I am not sure if I should or can do this in this case.
Thanks,
Miguel
I am trying to implement a new class based on
System.Web.HttpPostedFileBase so I can create a two directional
mapping between byte[] File and HttpPostedFileBase. So I have the
following:
public class HttpFile : HttpPostedFileBase, IDisposable {
public override int ContentLength { get { return (int)
this.InputStream.Length; } }
public override string ContentType { get { return
this._ContentType; } set { _ContentType = value; } }
private string _ContentType;
public override string FileName { get { return base.FileName; }
set { _FileName = value; } }
private string _FileName;
public override Stream InputStream {
get {
if (_Stream == null) {
_Stream = new FileStream(_FileName, FileMode.Open,
FileAccess.Read, FileShare.Read);
}
return _Stream;
}
}
private FileStream _Stream;
public HttpFile(string fileName, string contentType) {
this._ContentType = contentType;
this._FileName = fileName;
} // HttpFile
public void Dispose() {
if (_Stream != null) {
try { _Stream.Dispose(); } finally { _Stream = null; }
}
} // Dispose
public override void SaveAs(String filename) {
File.WriteAllBytes(filename, File.ReadAllBytes(_FileName));
} // SaveAs
}
I need to be able to create an HttpFile where its stream is taken from
a byte[] object.
How can I do this?
I am a little bit confused about this.
Note: in ContentType and FileName properties I added the "set" code.
I am not sure if I should or can do this in this case.
Thanks,
Miguel