AnsweredAssumed Answered

server error in image updoad

Question asked by vivek4alf on Oct 14, 2008
please give me solution….

hi, can anyone help me for this error, m using this code…
i don't know why am i getting server type error,
is something wrong in assosiationtype and childname property….



try{
            AuthenticationService sa = new AuthenticationService();
            sa.Url = "http://localhost:8080/alfresco/api/AuthenticationService";
            AuthenticationResult ar = sa.startSession("admin", "admin");
            string name = ar.username;
           
            if (name != null)
            {

                Label1.Text = name;
            }
            else
                Label1.Text = "not authenticated";
            string filepath = FileUpload1.PostedFile.FileName;
            string fileName = FileUpload1.FileName;

           
            RepositoryService objrepositoryservice = new RepositoryService();
            objrepositoryservice.Url = "http://localhost:8080/alfresco/api/RepositoryService";
            UsernameToken userToken = new UsernameToken(ar.username, ar.ticket);
            objrepositoryservice.RequestSoapContext.Security.Timestamp.TtlInSeconds = (long)300;
            objrepositoryservice.RequestSoapContext.Security.Tokens.Add(userToken);
            Alfresco.RepositoryWebService.Store objstore = new Alfresco.RepositoryWebService.Store();
            objstore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace;
            objstore.address = "spacestore";

            Alfresco.RepositoryWebService.ParentReference objparentreference = new Alfresco.RepositoryWebService.ParentReference();
            objparentreference.store = objstore;
            objparentreference.path = "/app:company_home";
            objparentreference.associationType = "{http://www.alfresco.org/model/content/1.0}contains"; ;
            objparentreference.childName = "{http://www.alfresco.org/model/content/1.0}" + fileName;

            NamedValue objnamedvalue = new NamedValue();
            objnamedvalue.name = "{http://www.alfresco.org/model/content/1.0}name";
            objnamedvalue.value = fileName;
            objnamedvalue.isMultiValue = false;
            NamedValue[] objproperties = new NamedValue[2];
            objproperties[0] = objnamedvalue;
            objnamedvalue = new NamedValue();
            objnamedvalue.name = "{http://www.alfresco.org/model/content/1.0}title";
            objnamedvalue.value = fileName;
            objnamedvalue.isMultiValue = false;
            objproperties[1] = objnamedvalue;
            CMLCreate objcmlcreate = new CMLCreate();
            objcmlcreate.parent = objparentreference;
            objcmlcreate.id = "1";
            objcmlcreate.type = "{http://www.alfresco.org/model/content/1.0}content";
            objcmlcreate.property = objproperties;
            ContentService objcontentservice = new ContentService();
            objcontentservice.Url = "http://localhost:8080/alfresco/api/ContentService";
            CML objcml = new CML();
            objcml.create = new CMLCreate[] { objcmlcreate };
            UpdateResult[] objupdateresult = objrepositoryservice.update(objcml);
            Alfresco.RepositoryWebService.Reference objreference = objupdateresult[0].destination;
            Alfresco.ContentWebService.Reference newcontentnode = new Alfresco.ContentWebService.Reference();
            newcontentnode.path = objreference.path;
            newcontentnode.uuid = objreference.uuid;
            Alfresco.ContentWebService.Store cwsstore = new Alfresco.ContentWebService.Store();
            cwsstore.address = "spacestore";
            objstore.scheme = Alfresco.RepositoryWebService.StoreEnum.workspace;
            newcontentnode.store = cwsstore;
            FileStream inputstream = new FileStream(filepath, FileMode.Open);
            int buffersize = (int)inputstream.Length;
            byte[] bytes = new byte[buffersize];
            inputstream.Read(bytes, 0, buffersize);
            inputstream.Close();
            ContentFormat objcontentformat = new ContentFormat();
            objcontentformat.mimetype = "image/jpeg";
            objcontentservice.write(newcontentnode, "{http://www.alfresco.org/model/content/1.0}content", bytes, objcontentformat);
            lblfileuploadstatus.Text = "good";
        }
        catch (Exception ex)
        {
            lblerror.Text = ex.Message;
        }

exception is server error———–updateresult is showing nullexception…

Outcomes