Recursos para Profesionales de TI > Página principal de foros > SharePoint - Development and Programming > Downloading attachment from Sharepoint List: object reference not set to instance of an Object error
Formular una preguntaFormular una pregunta
 

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

  • viernes, 03 de julio de 2009 14:32RachanaD Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    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, Moderadorviernes, 03 de julio 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 viernes, 03 de julio de 2009 14:37
    •  

Respuestas

  • lunes, 06 de julio de 2009 22:04RachanaD Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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 respuestaRachanaD lunes, 06 de julio de 2009 22:04
    •  

Todas las respuestas

  • viernes, 03 de julio de 2009 15:17Dave Hunter Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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
  • viernes, 03 de julio de 2009 15:47RachanaD Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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, 04 de julio de 2009 22:39RachanaD Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.
  • lunes, 06 de julio de 2009 22:04RachanaD Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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 respuestaRachanaD lunes, 06 de julio de 2009 22:04
    •