hi,
i was trying a tutorial from
http://www.15seconds.com/issue/021218.htm
and currently i'm trying the upload file function.. [[public bool SaveFile(string FullPath)]]
but i always get this error, can anyone know how to why this happen?
System.NullReferenceException: Object reference not set to an instance of an object.
at IDSSServer.IDSS.UploadFile(String FullPath) in c:\inetpub\wwwroot\idssserver\idss.asmx.cs:line 137
FullPath = "C:\\Inetpub\\wwwroot\\doc\\abc.txt"
this is the file tat i'm tyring to upload...
one more things tat i'm not sure about is where actually the file would be stored? i really hope tat someone can clear my doubts . thank you.
Web service............
Code:
[WebMethod]
[System.Web.Services.Protocols.SoapHeader("authHead er", Direction=System.Web.Services.Protocols.SoapHeader Direction.InOut,Required=true)]
public bool SaveFile(string FullPath) {
IDSSServer.User user = new IDSSServer.User(authHeader.Username, authHeader.Password, authHeader.Guid);
if(user.Login()) {
//valid login
return IDSSServer.DAL.SaveFile(FullPath, Microsoft.Web.Services.HttpSoapContext.RequestCont ext.Attachments[0].Stream);
} else {
throw new System.Web.Services.Protocols.SoapException("Inval id Login", new System.Xml.XmlQualifiedName("AuthHeader"));
}
}
IDDSServer..................
public static bool SaveFile(string path, System.IO.Stream contents) {
byte[] data = ConvertStreamToByteBuffer( contents );
if(System.IO.File.Exists(path)) System.IO.File.Delete(path);
System.IO.FileStream outfile = System.IO.File.OpenWrite(path);
outfile.Write(data, 0, data.Length);
outfile.Close();
return (System.IO.File.Exists(path));
}
public static byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream) {
if(theStream.Position>0 && theStream.CanSeek) theStream.Position=0;
int b1;
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
while((b1=theStream.ReadByte())!=-1) {
tempStream.WriteByte(((byte)b1));
}
return tempStream.ToArray();
}