本文介绍了应用属性资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨。
我正在尝试访问vs 2010 windows窗体中的properties.resources以返回一个特定文件,但是没有指定地址如下所示
我的代码是这样的:
public 流文件(字符串资源,字符串扩展名)
{
switch (扩展名)
{
案例 htm:
if ( ( String .Compare(resource, index)!= 0 )&&( String .Compare(resource, login)!= 0 ))
{
if (!Authenticate()) return null ;
}
WebOperationContext.Current.OutgoingResponse.ContentType = text / html ;
break ;
case js :
WebOperationContext.Current.OutgoingResponse.ContentType = text / javascript;
break ;
case css :
WebOperationContext.Current.OutgoingResponse.ContentType = text / css;
break ;
case png :
WebOperationContext.Current.OutgoingResponse.ContentType = image / png;
break ;
case ico :
WebOperationContext.Current.OutgoingResponse.ContentType = image / x-icon;
break ;
默认:
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.UnsupportedMediaType;
return new MemoryStream(Encoding.ASCII.GetBytes( 不支持文件类型), false );
}
string fileName = String .Format( @ C:\ Users \ Lopez \ Documents \ visualual studio 2010 \Projects \ Hello &\\ Hello &\\ Resources \ {0}。{1},资源,扩展名);
return new FileStream(fileName,FileMode.Open);
}
我的问题是如何更改此部分
string fileName = String.Format(@C:\Users\Lopez \Documents\visual studio 2010 \Projects\Hello \Hello \Resources \ {0}。{1},资源,扩展);
类似
Hello.Properties.Resources.state
thk
解决方案
Hi.
i'm trying to access the properties.resources in vs 2010 windows form to return a specif file, but whithout specifing the address as shown bellow
my code is this:
public Stream Files(string resource, string extension) { switch (extension) { case "htm": if ((String.Compare(resource, "index") != 0) && (String.Compare(resource, "login") != 0)) { if (!Authenticate()) return null; } WebOperationContext.Current.OutgoingResponse.ContentType = "text/html"; break; case "js": WebOperationContext.Current.OutgoingResponse.ContentType = "text/javascript"; break; case "css": WebOperationContext.Current.OutgoingResponse.ContentType = "text/css"; break; case "png": WebOperationContext.Current.OutgoingResponse.ContentType = "image/png"; break; case "ico": WebOperationContext.Current.OutgoingResponse.ContentType = "image/x-icon"; break; default: WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.UnsupportedMediaType; return new MemoryStream(Encoding.ASCII.GetBytes("File type not supported"), false); } string fileName = String.Format(@"C:\Users\Lopez\Documents\visual studio 2010\Projects\Hello\Hello\Resources\{0}.{1}", resource, extension); return new FileStream(fileName, FileMode.Open); }
My problem is how to change this part
string fileName = String.Format(@"C:\Users\Lopez\Documents\visual studio 2010\Projects\Hello\Hello\Resources\{0}.{1}", resource, extension);
in something like
Hello.Properties.Resources.state
thk
解决方案
这篇关于应用属性资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!