如何在c#.net中只读取rtf,doc文件 [英] How to make rtf, doc file readonly in c#.net

查看:291
本文介绍了如何在c#.net中只读取rtf,doc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们必须使用C#将数据发送给其他用户。但用户不应修改该文件。只有他可以读取文件。如果用户想要将文件发送给任何人,那么他可以发送,因为它是收到的文件而不修改它。

解决方案

我不认为那种控制你我说的是可能的,至少不是RTF文件。 此处 [ ^ ]是一种将Word文档设为只读的方法,但它很容易被规避。


实现它的两种方法:



< pre lang =c#> System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
fileInfo.IsReadOnly = true / false;





FileInfo上的IsReadOnly属性实际上是你需要做的位翻转在第二种方法中手动。



 File.SetAttributes(filePath,FileAttributes.ReadOnly / FileAttributes.Normal); 


In our project we have to send data to other users in C#. But users should not modify the file. Only he may able to read the file. If user wants to send the file to anyone then he may send as it is the received file without modifying it.

解决方案

I don't think the kind of control you're talking about is possible, at least not with an RTF file. Here[^] is a way of making a Word document read-only, but it's easily circumvented.


Two ways to achieve it:

System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
fileInfo.IsReadOnly = true/false;



IsReadOnly property on FileInfo essentially does the bit-flipping you would have to do manually in the second method.

File.SetAttributes(filePath, FileAttributes.ReadOnly/FileAttributes.Normal);


这篇关于如何在c#.net中只读取rtf,doc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆