Cообщество разработчиков на платформе Microsoft > Форумы > SharePoint - Development and Programming > Downloading attachment from Sharepoint List: object reference not set to instance of an Object error
Задайте вопросЗадайте вопрос
 

ОтвеченоDownloading attachment from Sharepoint List: object reference not set to instance of an Object error

  • 3 июля 2009 г. 14:32RachanaD Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     

    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.

    • ИзмененоMike Walsh MVPMVP, Модератор3 июля 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.
    • ИзмененоRachanaD 3 июля 2009 г. 14:37
    •  

Ответы

Все ответы