Downloading attachment from Sharepoint List: object reference not set to instance of an Object error<p>Hello,</p> <p>I am using the following code for downloading attachment from Sharepoint 2007 List.<br/>public static string downloadDoc(string listName, string ListItemID)<br/>        {<br/>            string filepath = &quot;&quot;;<br/>            try<br/>            {<br/>                AEPEx_MOSS.Lists ls = new AEPEx_MOSS.Lists();<br/>                //ls.Credentials = System.Net.CredentialCache.DefaultCredentials;<br/>                string MOSSWSUser = Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSWSUserID&quot;);<br/>                string MOSSWSPWD = Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSWSUserPWD&quot;);<br/>                string MOSSWSDomain = Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSWSUserDomain&quot;);</p> <p>                ls.PreAuthenticate = false;<br/>                System.Net.NetworkCredential cred = default(System.Net.NetworkCredential);<br/>                cred = new System.Net.NetworkCredential(MOSSWSUser, MOSSWSPWD, MOSSWSDomain);<br/>                ls.Credentials = cred;<br/>                SPSecurity.RunWithElevatedPrivileges(delegate()<br/>                {<br/>                    XmlNode ra = default(XmlNode);<br/>                    ra = ls.GetAttachmentCollection(listName, ListItemID);<br/>                    string url = ra.InnerText;<br/>                    SPSite site = new SPSite(Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;LIST_URL&quot;));<br/>                    SPWeb web = site.OpenWeb();<br/>                    SPFile list = web.GetFile(url);<br/>                    string fn = list.Name;<br/>                    string guid = null;<br/>                    guid = System.Guid.NewGuid().ToString();<br/>                    if (!Directory.Exists(Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSAttachmentPath&quot;) + guid))<br/>                    {<br/>                        Directory.CreateDirectory(Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSAttachmentPath&quot;) + guid);<br/>                        byte[] b = list.OpenBinary();<br/>                        FileStream s = System.IO.File.Create(Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSAttachmentPath&quot;) + guid + &quot;\\&quot; + list.Name);<br/>                        filepath = Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSAttachmentPath&quot;) + guid + &quot;\\&quot; + list.Name;<br/>                        s.Write(b, 0, b.Length);<br/>                        s.Dispose();<br/>                        s.Close();<br/>                    }<br/>                }<br/>                );<br/>            }<br/>            catch (Exception ex)<br/>            {<br/>                AEPEx.Integration.BizTalk.CommonUtilities.Logger.WriteError_Filenet(&quot;Exception getting Attachment &quot; + ex.Message, EventLogEntryType.Error);</p> <p>            }<br/>            return filepath;<br/>        }</p> <p>I am getting an error:&quot;Object reference not set to Instance of an object&quot; error.<br/>When I run this code from a WIndows app, the ATtachment is getting downloaded properly. However when i run this code by adding reference to a Biztalk APp, I am getting the error,at the line when the new SP Site is getting created. I have searched all over the internet without any solution.</p>© 2009 Microsoft Corporation. All rights reserved.Mon, 06 Jul 2009 22:04:56 Z25d74cc0-2fe7-40b3-b29b-f14f43722a3fhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#25d74cc0-2fe7-40b3-b29b-f14f43722a3fhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#25d74cc0-2fe7-40b3-b29b-f14f43722a3fRachanaDhttp://social.technet.microsoft.com/Profile/en-US/?user=RachanaDDownloading attachment from Sharepoint List: object reference not set to instance of an Object error<p>Hello,</p> <p>I am using the following code for downloading attachment from Sharepoint 2007 List.<br/>public static string downloadDoc(string listName, string ListItemID)<br/>        {<br/>            string filepath = &quot;&quot;;<br/>            try<br/>            {<br/>                AEPEx_MOSS.Lists ls = new AEPEx_MOSS.Lists();<br/>                //ls.Credentials = System.Net.CredentialCache.DefaultCredentials;<br/>                string MOSSWSUser = Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSWSUserID&quot;);<br/>                string MOSSWSPWD = Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSWSUserPWD&quot;);<br/>                string MOSSWSDomain = Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSWSUserDomain&quot;);</p> <p>                ls.PreAuthenticate = false;<br/>                System.Net.NetworkCredential cred = default(System.Net.NetworkCredential);<br/>                cred = new System.Net.NetworkCredential(MOSSWSUser, MOSSWSPWD, MOSSWSDomain);<br/>                ls.Credentials = cred;<br/>                SPSecurity.RunWithElevatedPrivileges(delegate()<br/>                {<br/>                    XmlNode ra = default(XmlNode);<br/>                    ra = ls.GetAttachmentCollection(listName, ListItemID);<br/>                    string url = ra.InnerText;<br/>                    SPSite site = new SPSite(Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;LIST_URL&quot;));<br/>                    SPWeb web = site.OpenWeb();<br/>                    SPFile list = web.GetFile(url);<br/>                    string fn = list.Name;<br/>                    string guid = null;<br/>                    guid = System.Guid.NewGuid().ToString();<br/>                    if (!Directory.Exists(Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSAttachmentPath&quot;) + guid))<br/>                    {<br/>                        Directory.CreateDirectory(Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSAttachmentPath&quot;) + guid);<br/>                        byte[] b = list.OpenBinary();<br/>                        FileStream s = System.IO.File.Create(Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSAttachmentPath&quot;) + guid + &quot;\\&quot; + list.Name);<br/>                        filepath = Microsoft.SSO.Utility.SSOConfigHelper.Read(&quot;AEPEx_CarrierInterface&quot;, &quot;MOSSAttachmentPath&quot;) + guid + &quot;\\&quot; + list.Name;<br/>                        s.Write(b, 0, b.Length);<br/>                        s.Dispose();<br/>                        s.Close();<br/>                    }<br/>                }<br/>                );<br/>            }<br/>            catch (Exception ex)<br/>            {<br/>                AEPEx.Integration.BizTalk.CommonUtilities.Logger.WriteError_Filenet(&quot;Exception getting Attachment &quot; + ex.Message, EventLogEntryType.Error);</p> <p>            }<br/>            return filepath;<br/>        }</p> <p>I am getting an error:&quot;Object reference not set to Instance of an object&quot; error.<br/>When I run this code from a WIndows app, the ATtachment is getting downloaded properly. However when i run this code by adding reference to a Biztalk APp, I am getting the error,at the line when the new SP Site is getting created. I have searched all over the internet without any solution.</p>Fri, 03 Jul 2009 14:32:25 Z2009-07-03T14:52:30Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#be47b03d-babc-4048-8aac-64f6bfa68e7bhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#be47b03d-babc-4048-8aac-64f6bfa68e7bDave Hunterhttp://social.technet.microsoft.com/Profile/en-US/?user=Dave%20HunterDownloading attachment from Sharepoint List: object reference not set to instance of an Object errorDoes the account that run Biztalk app runs under has rights in SharePoint?  The best solution would be to create a custom web service with this functionality and get Biztalk to call it.<hr class="sig">My SharePoint Blog - <a href="http://www.davehunter.co.uk/blog">http://www.davehunter.co.uk/blog</a>Fri, 03 Jul 2009 15:17:47 Z2009-07-03T15:17:47Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#8729479e-12e5-4747-b984-cd25c1b2cfe3http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#8729479e-12e5-4747-b984-cd25c1b2cfe3RachanaDhttp://social.technet.microsoft.com/Profile/en-US/?user=RachanaDDownloading attachment from Sharepoint List: object reference not set to instance of an Object errorHow do I go about creating a custom WS to do this?Please suggest.Also how will creating a WS resolve the security issue.Fri, 03 Jul 2009 15:47:34 Z2009-07-03T15:51:20Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#e5fcab7a-986d-4bcc-b3ad-7e1590c82b0fhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#e5fcab7a-986d-4bcc-b3ad-7e1590c82b0fRachanaDhttp://social.technet.microsoft.com/Profile/en-US/?user=RachanaDDownloading attachment from Sharepoint List: object reference not set to instance of an Object errorHello, I have created a web service for downloading the attachment from Sharepoint.I have set it to run under a user which is an Admin for the MOSS app. However I still get this error: Exception getting Attachment The Web application at http://:1002/_vti_bin/lists.asmx could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application. Please suggest.Sat, 04 Jul 2009 22:39:00 Z2009-07-04T22:39:00Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#07f35e94-2a8f-475c-95cd-1dc2fe1c6892http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/25d74cc0-2fe7-40b3-b29b-f14f43722a3f#07f35e94-2a8f-475c-95cd-1dc2fe1c6892RachanaDhttp://social.technet.microsoft.com/Profile/en-US/?user=RachanaDDownloading attachment from Sharepoint List: object reference not set to instance of an Object errorHello,<br/>I was able to make the WS work. The way to do it is to share the same Application pool for the web service as of the Sharepoint Shared Service.<br/>Mon, 06 Jul 2009 22:04:52 Z2009-07-06T22:04:52Z