Peter said:
[...]
file.Method = value;
file.MetaData.FileName = "name";
But, when I get to assigning values to the subclass, I get a null
reference exception (I didn't instantiate the subclass).
I am not quite sure how i should be doing this?
Doing what? What is it really that you are trying to do here?
The only code you showed was the code that works.
Sorry...I didn't notice in your post you're trying to access members of
FileStream that don't exist. Obviously the above statement of mine is
incorrect.
Still, it's not clear from your post why you would think doing that
would work. If the variable is declared as "FileStream", you can't
access anything in the instance except members of the FileStream class
(either those declared by the FileStream class, or inherited by the
FileStream class from its base classes).
As I wrote before, please post a concise-but-complete code example, and
please rewrite your question so that it's specific and clearly states
what it is exactly you're trying to accomplish.
Pete
OK, thanks for the response.
I am designing an WCF service for file uploads (in this case, images).
As you have observed, I have created a class that allows me to both do
the stream and include metadata information in my parameter argument.
[DataContract(Namespace = "FileTransfer")]
public class FileTransfer
{
[DataMember]
public string GetUploadStatus;
[DataMember]
public int UploadFile;
[DataMember]
public FileTransferInfo FileInfo;
[DataMember]
public Stream FileByteStream;
}
[DataContract(Namespace = "FileTransfer")]
public class FileTransferInfo
{
private string _guid;
private int _flag;
private long _fileSize;
private string _fileName;
private DateTime _lastUpdate;
private FileTypeEnum _fileType;
private object _sync = new object(); // single lock for both
fields
public FileTransferInfo() { }
public FileTransferInfo(string _guid, int _flag, long
_fileSize, string _fileName, DateTime _lastUpdate, FileTypeEnum
_fileType)
{
this.Guid = _guid;
this.Flag = _flag;
this.FileSize = _fileSize;
this.FileName = _fileName;
this.LastUpdate = _lastUpdate;
this.FileType = _fileType;
}
[DataMember(Name = "Guid", Order = 3, IsRequired = true)]
public string Guid
{
get { lock (_sync) { return _guid; } }
set { lock (_sync) { _guid = value; } }
}
//ETC. Other getters and setters below...
}
Now, In my CodeBehind, I want to use the WCF service to
upload a file such that:
FileTransferServiceClient upload = new FileTransferServiceClient();
HttpPostedFile m_objFile = default(HttpPostedFile);
FileTransfer transmit = null;
// Loop Through HttpPostedFile And Assign Values
transmit.FileByteStream = m_objFile.InputStream;
transmit.FileInfo.Guid = Guid.NewGuid().ToString();
transmit.FileInfo.Flag = default(int);
transmit.FileInfo.FileSize = m_objFile.ContentLength;
transmit.FileInfo.FileName = m_objFile.FileName;
transmit.FileInfo.LastUpdate = DateTime.Now;
int retParam = upload.UploadFile(transmit);
// End loop
//NOTE: The loop fails when it gets to FileInfo.Guid and throws
//a null reference exception. When I step through in watch view,
//FileInfo is null.
Thanks again.