指定指向.net项目中的文件夹的路径 [英] specify path leading to a folder within the .net project
问题描述
我被困住了.请帮帮我.
1.在c#.net中创建一个Web应用程序,我的目标形式是编写两个xml文件,一个是公钥,另一个是私钥,并将它们放置在项目内的文件夹中(这里我将其命名为f_upload和f_upload1 ),但没有发生
2.此代码不会阻塞任何错误,但不会产生所需的文件
3.问题在#1和#2线上吗?正确的行是什么?
4.剩下代码#1和#2是否可以生成所需的文件?
I am stuck. Please help me out.
1.its a web application in c#.net and my aim form the code below is to make two xml files, one of public key and another private key and place them in a folder within the project(here I have named it f_upload and f_upload1)but it''s not happening
2.this code is not choking any error but not producing the desired files
3.is the problem on the line #1 and #2? What would be the correct line?
4.leaving #1 and #2 is the rest of the code okay to generate the desired files?
public class Class1
{
public static bool GenerateRsa(int size)
{
/* #1 */ string privateKeyPath = System.Web.HttpContext.Current.Server.MapPath("f_upload\\");
/* #2 */ string publicKeyPath = System.Web.HttpContext.Current.Server.MapPath("f_upload1\\");
//stream to save the keys
FileStream fs = null;
StreamWriter sw = null;
//create RSA provider
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(size);
try
{
//save private key
fs = new FileStream(privateKeyPath, FileMode.Create, FileAccess.Write);
sw = new StreamWriter(fs);
sw.Write(rsa.ToXmlString(true));
sw.Flush();
}
finally
{
if (sw != null) sw.Close();
if (fs != null) fs.Close();
}
try
{
//save public key
fs = new FileStream(publicKeyPath, FileMode.Create, FileAccess.Write);
sw = new StreamWriter(fs);
sw.Write(rsa.ToXmlString(false));
sw.Flush();
}
finally
{
if (sw != null) sw.Close();
if (fs != null) fs.Close();
}
rsa.Clear();
return true;
}
推荐答案
您可以使用以下&我认为这不会有任何问题.
You can use like below & i think, it will not make any problem.
string privateKeyPath = Server.MapPath("~/f_upload/1.xml");
string publicKeyPath = Server.MapPath("~/f_upload1/1.xml");
您必须有两个文件夹f_upload& f_upload1,位于项目的根目录中.
you have to, two folder f_upload & f_upload1, in the root directory in your project.
您可能想尝试此处介绍的技术:
解析多文件夹网站中的路径 [ ^ ]
You might want to try the technique described here:
Resolving Paths in a Multi-Folder WebSite[^]
谢谢....我应该以这种方式调用该函数吗?
字符串s = obj.ResolvePath("C:\ Documents and Settings \ Soum \ My Documents \ Visual Studio 2008 \ WebSites \ RSA \ f_upload",在这里做什么?);
thanks....would it be this way i should call the function?
string s=obj.ResolvePath("C:\Documents and Settings\Soum\My Documents\Visual Studio 2008\WebSites\RSA\f_upload",whatdoigivehere?);
这篇关于指定指向.net项目中的文件夹的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!