简体   繁体   English

在远程服务器上打开文件[路径问题]

[英]Open a file on remote server [path issue]

I'm developing a vehicle storage application. 我正在开发车辆存储应用程序。 One feature is being able to store documents in different formats (word, excel, pdf) on a remote server WITHOUT having to map the server as separate drive. 一种功能是能够将不同格式(word,excel,pdf)的文档存储在远程服务器上,而不必将服务器映射为单独的驱动器。
Everything works fine if the file to be opened is on the local hard drive (ie, "C:/Documents/FileToOpen.docx"), but I can't figure out the path structure for a path (ie, "C:/Documents/FileToOpen.docx" on server "SERVER06"). 如果要打开的文件在本地硬盘驱动器上(即“ C:/Documents/FileToOpen.docx”),则一切正常,但是我无法弄清路径的路径结构(即“ C:/服务器“ SERVER06”上的Documents / FileToOpen.docx”)。 I've tried "//SERVER06/C/Documents/FileToOpen.docx" and permutations thereof, but no joy so far. 我已经尝试过“ //SERVER06/C/Documents/FileToOpen.docx”及其排列,但到目前为止没有任何乐趣。

public class Attachments extends javax.swing.JFrame {

    String docPath = "C:/Program Files/Microsoft Office/Office14/WINWORD.EXE";
    String excelPath = "C:/Program Files/Microsoft Office/Office14/EXCEL.EXE";
    String pdfPath = "C:/Program Files/Adobe/Reader 11.0/Reader/AcroRd32.exe";

    /**
     * Creates new form Attachments
     */
    public Attachments() {
        initComponents();

        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        this.setResizable(false);

    }

    public void setList(Set attachmentList) {
        DefaultListModel model = new DefaultListModel();
        Iterator i = attachmentList.iterator();
        int counter = 0;
        while (i.hasNext()) {
            model.add(counter, (Attachment) i.next());
            counter++;
        }
        listAttachments.setModel(model);
    }

    //form generation

    private void btnViewActionPerformed(java.awt.event.ActionEvent evt) {
        Attachment a = (Attachment) listAttachments.getSelectedValue();
        String type = a.getAttachmentUrl().substring(a.getAttachmentUrl().indexOf("."));
        String prog = "";
        if (type.substring(0, 2).equals(".d")) {
            prog = docPath;
        } else if (type.substring(0, 2).equals(".p")) {
            prog = pdfPath;
        } else if (type.substring(0, 2).equals(".x")) {
            prog = excelPath;
        }

        String commandString = "\"" + prog + "\" \"" + a.getAttachmentUrl() + "\"";
        Runtime rt = Runtime.getRuntime();
        try {
            rt.exec(commandString);
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
    }

    private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt) {
        this.setVisible(false);
        this.dispose();
    }

Is there a way to accomplish this? 有没有办法做到这一点?

Assuming your server is using Windows operating system, the server firstly need to share the folder that contains the documents. 假设您的服务器使用Windows操作系统,则服务器首先需要共享包含文档的文件夹。 To do this, go to the server, select the folder, right click and choose 'share'. 为此,请转到服务器,选择文件夹,右键单击并选择“共享”。 To verify, go back to the client machine, open windows explorer and type \\SERVER06 If your folder sharing is successful, you should see a folder called 'Documents'. 若要进行验证,请返回到客户端计算机,打开Windows资源管理器并键入\\ SERVER06。如果文件夹共享成功,则应该看到一个名为“文档”的文件夹。 If all these are fine this far, your application just need to open the file using "\\\\SERVER06\\Documents\\FileToOpen.docx". 如果到目前为止所有这些都还不错,则您的应用程序只需使用“ \\\\ SERVER06 \\ Documents \\ FileToOpen.docx”打开文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM