如何在vb.net代码中保存文件 [英] How do I save a file in vb.net code

查看:109
本文介绍了如何在vb.net代码中保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有问题,我有一个代码可以在我的电脑中保存一个文本文件,目的地是:



 C:\ Users \Georgegas \Desktop\Log.txt 





问题不在于代码和文件位置。我想在其他电脑上使用它,不仅在我的电脑上,它的名字是GeorgeGkas:P



C#我会写

 C:\ Users \%USERPROFILE%\Desktop\Log.txt 





但在 VB.Net 中对我不起作用!



那么如何设置我的目的地以保存我的文件在不同名称的计算机上?



我希望你们理解我的问题!

解决方案

要保存在另一台计算机上,你需要拥有该文件夹的访问权限和写入权限。

例如 \\OtherComputer\LogFiles 前提是您可以访问LogFiles文件夹。


 < span class =code-comment>' 声明 
公共 共享 功能 GetFolderPath(_
文件夹 As Environment.SpecialFolder _
作为 字符串





并按照以下方式使用





 进口系统

示例
< span class =code-keyword>公开 共享 Sub Main()
Console.WriteLine()
Console.WriteLine( GetFolderPath:{0},Environment.GetFolderPath(Environment.SpecialFolder.System))
结束 Sub ' Main
结束 ' 示例





,如微软网站所示。


OI找到它!你只需添加

 + Environment.UserName.ToString + 





示例

   C:\ Users \ + Environment.UserName.ToString +   \ AppData \ Rooaming\program.exe 


Hello guys,

I have a problem ,I have a code that saves a text file in my computer with the destination :

C:\Users\Georgegas\Desktop\Log.txt



The problem isn't about the code as it is for the location of the file. I want to use it in other computers not only on my PC , which its name is "GeorgeGkas" :P

In C# i would write that

C:\Users\%USERPROFILE%\Desktop\Log.txt



but in VB.Net that doesn't work for me!

So how do I set my destination to save my file in computers with different name?

I hope you guys understand my problem!

解决方案

To save in another computer, you need to have access and write permissions to that folder.
For e.g. \\OtherComputer\LogFiles provided you have access to the LogFiles folder.


'Declaration
Public Shared Function GetFolderPath ( _
	folder As Environment.SpecialFolder _
) As String



and use it like following



Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
   End Sub 'Main
End Class 'Sample



as suggested in microsoft website.


O I find it! You just add

+ Environment.UserName.ToString + 



Example

"C:\Users\" + Environment.UserName.ToString + "\AppData\Roaming\program.exe"


这篇关于如何在vb.net代码中保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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