Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > .NET Web Services
|
.NET Web Services Discussions about .NET XML Web Service technologies including ASMX files, WSDL and SOAP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Web Services section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2005, 11:37 AM
Registered User
 
Join Date: Dec 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default error in upload function

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();
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
File upload error balesh.mind ASP.NET 2.0 Professional 2 August 20th, 2007 02:52 PM
ASP Upload Error saurabhj Classic ASP Professional 1 May 5th, 2007 12:53 AM
file upload error Ashleek007 Beginning PHP 2 June 8th, 2004 05:44 PM
Upload Error Message isai Classic ASP Basics 0 September 10th, 2003 10:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.