Pour les professionnels de l’informatique > Forums - Accueil > SharePoint - Development and Programming > Downloading attachment from Sharepoint List: object reference not set to instance of an Object error
Poser une questionPoser une question
 

TraitéeDownloading attachment from Sharepoint List: object reference not set to instance of an Object error

  • vendredi 3 juillet 2009 14:32RachanaD Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     

    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.

    • ModifiéMike Walsh MVPMVP, Modérateurvendredi 3 juillet 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.
    • ModifiéRachanaD vendredi 3 juillet 2009 14:37
    •  

Réponses

Toutes les réponses

  • vendredi 3 juillet 2009 15:17Dave Hunter Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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
  • vendredi 3 juillet 2009 15:47RachanaD Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    How do I go about creating a custom WS to do this?Please suggest.Also how will creating a WS resolve the security issue.
  • samedi 4 juillet 2009 22:39RachanaD Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    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.
  • lundi 6 juillet 2009 22:04RachanaD Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    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.
    • Marqué comme réponseRachanaD lundi 6 juillet 2009 22:04
    •