導航:首頁 > 文件教程 > aspnet寫入文件

aspnet寫入文件

發布時間:2023-04-29 02:11:08

1. 一個關於asp.net的問題

你沒有裝.net框架消信或安裝順序不對,應該先裝框架然後裝iis,一般重裝差咐過iis容易出現此情況.可以在.net的命令行下用aspnet_regiis -i命令修復拿慶輪

2. 用aspnet

在 模型中 vs 已經完全脫離了編譯而成為了一個徹底的ide 算是一個不小的改動 其中更是取消了有關Web Application的概念 使得習慣了vs 的人剛開始的時候會有一些摸不著頭腦 下面簡單說一下我在使用過程中自己總結的 算是一點經驗

新建web工程並且位置是文件系統的時候 vs 只是幫你建好了一個sln文件 這個東西只是指引m *** uild 如何進行編譯的 過程是 ide 調用 m *** uild m *** uild解析sln文件 m *** uild調用aspnet_piler exe進行網站的編譯 所以aspnet_piler exe只是負責進行網站的編譯的

預編譯的概念在framework 裡面就存在了 vs 中的預編譯指的是將頁面對應的cs/vb文件與resx文件編譯後統一集成到一個dll中放到bin目錄下 將aspx文件直接拷貝過去 這樣做會留下隱患 因為aspx文件就直接暴露在最後的發行包中 如果完全是codeb behind模型還好 只能改改界面 如果採用了頁面上的來生成頁面 源代碼就暴露了 針對這些問題 vs 採用了一種新的模式

請參看ASP NET 編譯工具 (Aspnet_piler exe) 這篇文章了解對各種文件的處理方式

IDE發布

vs 中選擇 生成 〉發布網站 在對話框中的操作將映射到aspnet_piler exe的參數中 可更新的發布對應 u 其他選項類似 請參考上面的文章了解

注意 發布時將忽略nfig中的debug?問騁簧晌薜魘孕畔⒌奈募?

手工編譯

簡單說來 如果是無更新發布模式編譯 appcode下面的class編譯成dll放在bin下 頁面內容清空位置不變作佔位用 同時頁面被編譯成一個隨機名稱的dll 增加一個同piled文件到bin目錄下 內容大概如下

<?xml version= encoding= utf ?>

<preserve resultType= virtualPath= /Forum/AdminList aspx hash= c filehash= f d c flags= assembly= App_Web_hmrycg w type= ASP forum_adminlist_aspx >

<filedeps>

<filedep name= /Controls/footer ascx />

<filedep name= /Controls/header ascx />

<filedep name= /Forum/AdminList aspx />

<filedep name= /Forum/AdminList aspx cs />

<filedep name= /Forum/menu ascx />

<filedep name= /Forum/menu ascx cs />

</filedeps>

</preserve>

裡面只是列出了頁面上的customcontrol 這里已經完成了和masterfile的映射 這樣最大限度的保護了頁面的敏感信息 發布過的網站中只能看見一堆文件名了 可更新的發布模式與vs 類似 頁面就直接拷貝過來不予編譯了

講了一堆原理 下面說一下aspnet_piler exe的調用方法 這是我使用的例子

我的開發目錄是這樣的

Project/

library/

devroot/

pubroot/

proj sln

使用的命令如下

aspnet_piler v / p devroot f pubroot

分析

v / 指明了iis的虛擬目錄

p devroot 表示代碼實際位置

pubroot 指明了要發布的位置

f 表示強制改寫目標位置

lishixin/Article/program/net/201311/13677

3. 如何解決寫入XML文件時路徑訪問被拒絕

原因及解決方案:
此為文件寫入許可權問題,可如下操作解決(XP系統IIS5下嘗試可行)
1、資源管理器->工具->文件夾選項->查看 不選"使用簡單文件共享"
2、右擊該xml文件(或者該文件所在文件夾),選"屬性"點"安全"添加"aspnet",選中「寫入」賦予寫入許可權,或者選"完全控制",然後確定即可。

以下為網路獲取在windows2003伺服器IIS6下出現該錯誤提示的參考解決方案,在此摘錄僅供備份參考:

解決方案一
在需要進行讀寫操作的目錄下添加Network Service這個帳號,
由於在iis 6.0中,默認的應用程序池中的標示用的是Network Service,
所以在進程中是使用Network Service這個帳號運行來運行w3wp.exe進程,
而當我們在運行VS 2003的時候需要對某一個目錄下進行讀寫操作,
看了一下該文件夾,發現沒有Network Service,添加上該賬號,同時選上FULL CONTROL,問題解決,

解決方案二
在IIS6.0中的默認應用程序池-->屬性-->標示中把Net Service改成Local System該問題也可以解決

4. ASP.NET 操作word文檔(讀寫),怎麼實現

展示word文件這個網上不少例子。但是寫入word制定位置就是操作word文檔了。1.這個隱約記得是把word文檔分成好幾個區域實現操作,但這個不知道具體思路。
2,。如果客戶允許,可是加個連接或按鈕,「編輯文檔」。轉到文本編輯器裡面。
http://www.haoxiai.net/wangzhanzuo/aspnet/53267.html
這裡面多少有點原理。樓主看看

5. aspnet2005如何對word文檔進行操作

你安裝完vs2005 tool for office後,在新建項目就有word模板了。。
你就可以對word進行操作了。

補充:
首先引入類庫,Microsoft.Office.Interop.Word,然後進行編程。代碼如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;

using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;

namespace WordTest
{
public partial class Form1 : Form
{
object strFileName;
Object Nothing;
Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Document myWordDoc;
string strContent = "";

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
createWord();
//openWord();
}

private void createWord()
{
strFileName = System.Windows.Forms.Application.StartupPath + "test.doc";
if (System.IO.File.Exists((string)strFileName))
System.IO.File.Delete((string)strFileName);
Object Nothing = System.Reflection.Missing.Value;
myWordDoc = myWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

#region 將資料庫中讀取得數據寫入到word文件中

strContent = "你好\n\n\r";
myWordDoc.Paragraphs.Last.Range.Text = strContent;

strContent = "這是測試程序";
myWordDoc.Paragraphs.Last.Range.Text = strContent;

#endregion

//將WordDoc文檔對象的內容保存為DOC文檔
myWordDoc.SaveAs(ref strFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//關閉WordDoc文檔對象
myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
//關閉WordApp組件對象
myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);

this.richTextBox1.Text = strFileName + "\r\n" + "創建成功";

}
private void openWord()
{
fontDialog1.ShowDialog();
System.Drawing.Font font = fontDialog1.Font;
object filepath = "D:\\asp.docx";
object oMissing = System.Reflection.Missing.Value;
myWordDoc = myWordApp.Documents.Open(ref filepath, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
myWordDoc.Content.Font.Size = font.Size;
myWordDoc.Content.Font.Name = font.Name;
myWordDoc.Save();
richTextBox1.Text = myWordDoc.Content.Text;

myWordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
myWordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
}

}

6. ASP.NET創建文件並寫入內容

在ASP NET中 文件處理的整個過程都是圍繞著System IO 這個名稱空間展開的 這個名稱空間中具有執行文件讀 寫所需要的類 本文從最基本的操作開始 解釋在ASP NET中文件處理的概念 包括如從一個文件中讀取內容 如何向一個文件中寫入內容和如何刪除一個文件 前面已經提到 要想在ASP NET 頁面中進行文件處理 必須要有 System IO 名稱空間 所以 第一步就是引入這個名稱空間 <%@ Import Namespace= System IO %>下一步 就是創建一個文本文件 並將這個文本文件分配給一個流書寫對象 這樣就可以向文本文件中寫入內容了 用以下一段代碼來完成這個任務 writefile aspx<%@ Import Namespace= System IO %><%Response write( Writing the content into Text File in ASP NET<BR> ) 聲明流書寫對象Dim strwriterobj As StreamWriter 創建文本文件 分配textfile對象strwriterobj= File CreateText( c:aspnet txt ) 寫入內容strwriterobj WriteLine( Wele to wonderfull world of ASP NET Programming ) 完成櫻悔操作 關閉流對象strwriterobj CloseResponse write( Done with the creation of text file and writing content into it )%>這樣就完成了!現在讓我們繼續進行下一個任務 從剛才創建的文本文件中讀取內容 從文件中讀取內容從文件中讀取內容與向文件中寫入內容大致相同 只是要注意一下下面的兩件事 文件讀取使用StreamReader類 當使用了Readline方法時 將要被讀取的文本文件的結尾處會用一個空字元串( )來標記 現在開始編寫代碼從前面創建的aspnet txt 文件中讀取內容 readfile aspx<%@ Import Namespace= System IO %><%Response write( Reading the content from the text file ASPNET TXT<br> ) 創建流讀取對象Dim streamreaderobj As StreamReader 聲明變數 以存放從文件中讀取的內容Dim filecont As String 打開文本文件 分配給流讀亂判取對象streamreaderobj = File OpenText( c:aspnet txt ) 逐行讀取文件內容Dofilecont = streamreaderobj ReadLine()Response Write( filecont & <br> )Loop Until filecont = 完成讀取操作後 關閉流讀取對象streamreaderobj CloseResponse write( <br>Done with reading the content from the file aspnet txt )%>刪除文件在ASP NET中刪除文件也非常簡單和直觀 System IO名稱空間中的 File (文件)類有一個Delete方法用來刪除文件 它把文件名作為一個自變數來傳遞 以下代碼就演示了在ASP NET中進行文件嘩頌改刪除的步驟 Filedelete aspx<%@ Import Namespace= System IO %><%File Delete( c:aspnet txt )Response write( The File aspnet is deleted successfully !!! )%> lishixin/Article/program/ASP/201311/21860

7. asp.net文件寫入許可權問題

你的路徑寫錯了
你用SERVER.PATH("AAAAA.TXT");試試行不行

8. ASP.NET安裝部署之導入項目圖解

將VbNetTest項目的輸出添加到部署項目中(假如你的虛擬做吵目錄是SQLANDASPNet)

在 文件系統編輯器 中 選灶早擇純辯侍 Web 應用程序文件夾 在 操作 菜單上 指向 添加 然後選擇 項目輸出

9. asp.net注冊頁面數據寫入資料庫問題。我用的是ACCESS資料庫

是不是SQL語句錯了。 insert into 你的少個into 另外第3個參數RadioButtonList1.SelectedItem.Value是object類型的,需要先轉換成string才能往資料庫插入。

10. asp.net 讀寫配置文件Web.Config

給你一個例子,你瞧瞧:
<appSettings>
<add key="ConnectionString" value="server=192.168.19.250;database=hrms_test;uid=pmstest;pwd=pmstest" />
<add key="WebObjectPath" value="http://localhost/LMS/Files/" />
<add key="PhysicsObjectPath" value="E:/Files/"/>
<add key="SystemCode" value="12" />
<add key="OrganizationPath" value ="organization" />
</appSettings>
public static string ConnectionString
{
get { return System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString(); }
}

/// <summary>
/// 組織架構資料庫路徑
/// </summary>
public static string OrganizationPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["OrganizationPath"].ToString(); }
}

/// <summary>
/// 系統編碼
/// </summary>
public static string SystemCode
{
get { return System.Configuration.ConfigurationManager.AppSettings["SystemCode"].ToString(); }
}

/// <summary>
/// 物理上傳路徑
/// </summary>
public static string PhysicsObjectPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["PhysicsObjectPath"].ToString(); }
}

/// <summary>
/// 虛擬上傳路徑
/// </summary>
public static string WebObjectPath
{
get { return System.Configuration.ConfigurationManager.AppSettings["WebObjectPath"].ToString(); }
}

閱讀全文

與aspnet寫入文件相關的資料

熱點內容
小米刷機顯示系統找不到指定文件 瀏覽:528
蘋果手機小風扇圖app叫什麼 瀏覽:292
繁體中文輸入工具 瀏覽:916
pc桌面壁紙文件夾 瀏覽:473
微信怎麼添加群 瀏覽:781
40歲男人適合的微信名 瀏覽:925
編程里比例怎麼打 瀏覽:215
蘋果12兩個app如何分屏 瀏覽:592
ps下載完不是壓縮文件 瀏覽:362
電腦中的個人文件包括什麼 瀏覽:572
網路連接一般什麼密碼 瀏覽:199
java定時器quartz實例 瀏覽:259
稻殼excel文件太大怎麼弄 瀏覽:901
文件里的視頻如何保存到相冊 瀏覽:428
手機百度雲文件電腦 瀏覽:957
編程怎麼做到時鍾精準 瀏覽:912
錘子用過的壁紙在哪個文件里 瀏覽:468
qq網站安全性未知訪問不了怎麼辦 瀏覽:270
燕秀怎麼修改編程人名字 瀏覽:789
2012年天之眼導航升級 瀏覽:595

友情鏈接