0

我正在 Silverlight 中处理异常处理对话框。当抛出异常时,会弹出对话框,其中包含有关错误的详细信息,以及一个允许用户保存错误日志并将其发送给开发人员的按钮。当用户单击Save Error Log按钮时,会SaveFileDialog弹出一个并让用户浏览到他想要保存文件的位置。

如何获取C:\Folder\logfile.log所选文件的完整路径(例如)?该SafeFileName属性只给了我文件名(例如logfile.log)。

4

1 回答 1

3

You can't get the full path within an SL application due to being sandboxed. You could do this however within WPF since you have full access at that point.

That does not mean you can not save the file to the given location via the exposed Stream though. Complete example here.

            try 
            {  
                byte[] fileBytes = e.Result as byte[];  

                using ( Stream fs = (Stream)this.dialog.OpenFile() )  
                {  
                    fs.Write( fileBytes, 0, fileBytes.Length );  
                    fs.Close();  

                    this.tblError.Text = "File successfully saved!";  
                }  
            }  
            catch ( Exception ex )  
            {  
                this.tblError.Text = "Error getting result: " + ex.Message;  
            }  
于 2010-11-23T14:59:15.647 回答