예제 #1
0
        static void Main(string[] args)
        {
            if (SessionUtils.Session == null)
            {
                AuthInfo authInfo = AuthInfo.ReadAuthInfo();

                if (!string.IsNullOrWhiteSpace(authInfo.username) && !string.IsNullOrWhiteSpace(authInfo.password))
                {
                    SessionUtils.Session = SessionUtils.CreateSession(authInfo.serviceUrl, authInfo.username, authInfo.password);
                }
            }
            StartApp(args);
        }
예제 #2
0
        public static AlfResult UploadFile(string filePath)
        {
            try
            {
                if (File.Exists(filePath))
                {
                    AuthInfo authInfo = AuthInfo.ReadAuthInfo();
                    //IFolder rootFolder = session.GetRootFolder();
                    IFolder userHomeFolder = (IFolder)Session.GetObjectByPath("/" + AlfDefs.DEFAULT_DIR_NAME_USER_HOMES + "/" + authInfo.username);

                    // document name
                    string formattedName = Path.GetFileName(filePath);

                    // define dictionary
                    IDictionary <string, object> properties = new Dictionary <string, object>();
                    properties.Add(PropertyIds.Name, formattedName);

                    // define object type as document, as we wanted to create document
                    properties.Add(PropertyIds.ObjectTypeId, "cmis:document");

                    // read a empty document with empty bytes
                    // fileUpload1: is a .net file upload control
                    byte[]        datas         = File.ReadAllBytes(filePath);
                    string        mimeType      = MimeTypeMap.GetMimeType(Path.GetExtension(filePath));
                    ContentStream contentStream = new ContentStream
                    {
                        FileName = formattedName,
                        MimeType = mimeType,
                        Length   = datas.Length,
                        Stream   = new MemoryStream(datas)
                    };

                    // this statment would create document in default repository
                    userHomeFolder.CreateDocument(properties, contentStream, null);

                    return(new AlfResult(AlfResult.STATUS_OK, "Success"));
                }
                else
                {
                    return(new AlfResult(AlfResult.STATUS_FILE_NOT_FOUND, "File not found"));
                }
            }
            catch (Exception e)
            {
                return(new AlfResult(AlfResult.STATUS_EXCEPTION, e.StackTrace));
            }
        }