Inheritance: WebDavTypedCommand
        //**********************************************************************
        // Uploads the specified local file to the JCR
        //**********************************************************************
        private void UploadFile(String filePath,
            String destinationPath)
        {
            // Read the content of the file
            FileStream inputStream = new FileStream(filePath, FileMode.Open);
            int fileSize = (int)inputStream.Length;
            byte[] bytes = new byte[fileSize];
            inputStream.Read(bytes, 0, fileSize);
            inputStream.Close();

            // Get the actual file name
            String fileName = new FileInfo(filePath).Name;

            // Upload the file
            PutCommand put = new PutCommand(GetDavContext());
            put.setResourcePath(destinationPath
                                + '/'
                                + fileName);
            put.setRequestBody(bytes);

            // Determine if the WebDAV command worked successfully
            if (put.execute() != DavStatus.CREATED)
            {
                throw new Exception(
                    "PUT returned a wrong status when processing \""
                    + filePath
                    + "\" : "
                    + put.getStatus()
                    + " "
                    + Helper.WebDAVStatusToString(put.getStatus()));
            }
        }
Esempio n. 2
0
        private void makePut()
        {
            this.app.ActiveWorkbook.Save();

            try
            {
                String fileSystemName = getActiveDocumentFullName();
                String remoteFileName = fileSystemName.Substring(fileSystemName.IndexOf("\\" + workspace));
                remoteFileName = remoteFileName.Replace("\\", "/");
                remoteFileName = remoteFileName.Replace("%3F", "?");

                FileStream stream = new FileStream(fileSystemName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                long len = stream.Length;
                byte[] filedata = new byte[len];
                int readed = 0;
                while (readed < len)
                {
                    readed += stream.Read(filedata, 0, (int)(len - readed));
                }

                DavContext context = getContext();
                PutCommand put = new PutCommand(context);
                put.setResourcePath(remoteFileName);
                put.setRequestBody(filedata);
                int status = put.execute();
                if (status != DavStatus.CREATED)
                {
                    MessageBox.Show("Can't save file. Status: " + status, "Error",
                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("File saved successfully!", "Info",
                     MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Unhandled exception. " + exc.Message);
                MessageBox.Show(exc.StackTrace);
            }
        }
Esempio n. 3
0
        private void doPutFile(String localName, String remoteName, String contentType)
        {
            try
            {
                FileStream stream = new FileStream(localName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                long len = stream.Length;
                byte[] filedata = new byte[len];
                int readed = 0;
                while (readed < len)
                {
                    readed += stream.Read(filedata, 0, (int)(len - readed));
                }

                DavContext context = application.getContext();
                PutCommand put = new PutCommand(context);
                put.addRequestHeader(HttpHeaders.CONTENTTYPE, contentType);
                put.setResourcePath(remoteName);
                put.setRequestBody(filedata);
                int status = put.execute();
                if (status != DavStatus.CREATED)
                {
                    Utils.showMessageStatus(status);
                }
                else
                {
                    MessageBox.Show("File saved successfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ParentForm.Close();
                }
            }
            catch (FileNotFoundException ee)
            {
                MessageBox.Show("File read error!", "Can't read file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;

            }
        }