Resources for IT Professionals > Página Inicial dos Fóruns > SharePoint - Development and Programming > Downloading attachment from Sharepoint List: object reference not set to instance of an Object error
Fazer uma PerguntaFazer uma Pergunta
 

RespondidoDownloading attachment from Sharepoint List: object reference not set to instance of an Object error

  • sexta-feira, 3 de julho de 2009 14:32RachanaD Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Hello,

    I am using the following code for downloading attachment from Sharepoint 2007 List.
    public static string downloadDoc(string listName, string ListItemID)
            {
                string filepath = "";
                try
                {
                    AEPEx_MOSS.Lists ls = new AEPEx_MOSS.Lists();
                    //ls.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    string MOSSWSUser = Microsoft.SSO.Utility.SSOConfigHelper.Read("AEPEx_CarrierInterface", "MOSSWSUserID");
                    string MOSSWSPWD = Microsoft.SSO.Utility.SSOConfigHelper.Read("AEPEx_CarrierInterface", "MOSSWSUserPWD");
                    string MOSSWSDomain = Microsoft.SSO.Utility.SSOConfigHelper.Read("AEPEx_CarrierInterface", "MOSSWSUserDomain");

                    ls.PreAuthenticate = false;
                    System.Net.NetworkCredential cred = default(System.Net.NetworkCredential);
                    cred = new System.Net.NetworkCredential(MOSSWSUser, MOSSWSPWD, MOSSWSDomain);
                    ls.Credentials = cred;
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        XmlNode ra = default(XmlNode);
                        ra = ls.GetAttachmentCollection(listName, ListItemID);
                        string url = ra.InnerText;
                        SPSite site = new SPSite(Microsoft.SSO.Utility.SSOConfigHelper.Read("AEPEx_CarrierInterface", "LIST_URL"));
                        SPWeb web = site.OpenWeb();
                        SPFile list = web.GetFile(url);
                        string fn = list.Name;
                        string guid = null;
                        guid = System.Guid.NewGuid().ToString();
                        if (!Directory.Exists(Microsoft.SSO.Utility.SSOConfigHelper.Read("AEPEx_CarrierInterface", "MOSSAttachmentPath") + guid))
                        {
                            Directory.CreateDirectory(Microsoft.SSO.Utility.SSOConfigHelper.Read("AEPEx_CarrierInterface", "MOSSAttachmentPath") + guid);
                            byte[] b = list.OpenBinary();
                            FileStream s = System.IO.File.Create(Microsoft.SSO.Utility.SSOConfigHelper.Read("AEPEx_CarrierInterface", "MOSSAttachmentPath") + guid + "\\" + list.Name);
                            filepath = Microsoft.SSO.Utility.SSOConfigHelper.Read("AEPEx_CarrierInterface", "MOSSAttachmentPath") + guid + "\\" + list.Name;
                            s.Write(b, 0, b.Length);
                            s.Dispose();
                            s.Close();
                        }
                    }
                    );
                }
                catch (Exception ex)
                {
                    AEPEx.Integration.BizTalk.CommonUtilities.Logger.WriteError_Filenet("Exception getting Attachment " + ex.Message, EventLogEntryType.Error);

                }
                return filepath;
            }

    I am getting an error:"Object reference not set to Instance of an object" error.
    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.

    • EditadoMike Walsh MVPMVP, Moderadorsexta-feira, 3 de julho de 2009 14:52"i need help desperately, because it is urgent and " removed from Text. These are forums. If you are in a hurry call MS Customer Support Services. If you use forums be prepared to wait and don't push us.
    • EditadoRachanaD sexta-feira, 3 de julho de 2009 14:37
    •  

Respostas

  • segunda-feira, 6 de julho de 2009 22:04RachanaD Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    Hello,
    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.
    • Marcado como RespostaRachanaD segunda-feira, 6 de julho de 2009 22:04
    •  

Todas as Respostas

  • sexta-feira, 3 de julho de 2009 15:17Dave Hunter Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Does 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.
    My SharePoint Blog - http://www.davehunter.co.uk/blog
  • sexta-feira, 3 de julho de 2009 15:47RachanaD Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    How do I go about creating a custom WS to do this?Please suggest.Also how will creating a WS resolve the security issue.
  • sábado, 4 de julho de 2009 22:39RachanaD Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hello, 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.
  • segunda-feira, 6 de julho de 2009 22:04RachanaD Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    Hello,
    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.
    • Marcado como RespostaRachanaD segunda-feira, 6 de julho de 2009 22:04
    •