Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have made a simple page to add news to a site which has values title and link to be redirect.
I Have use xml for the purpose.
When i run code on local host it is working perfectly but when i deploy it on website it shows aceess denied error whenever i'm trying to save the file.
My XML file is
XML
<?xml version="1.0" encoding="utf-8"?>
<newsInfo>
  <news>
    <id>1</id>
    <title>AGM (Annual General Meeting) was held on 16th June (Saturday), New Executive Committee has taken charge.</title>
    <link>../contact.aspx</link>
  </news>
  <news>
    <id>2</id>
    <title>IETE Surat  center is thinking to hold its first examination center at SURAT in December 2012, For more Information please  send your feedback here.</title>
    <link>../contact.aspx</link>
  </news>
</newsInfo>



And code is
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["7856_UserID"] == null)
            {
                Response.Redirect("Default.aspx");

            }
            else
            {
                lblUserName.Text = "Welcome " + Convert.ToString(Session["7856_UserID"]) + "!";
                fillgrid();
            }
        }
    }
    protected DataTable retriveDetailsFromXML()
    {
        XDocument xmlDoc = XDocument.Load(Server.MapPath("~\\Data\\newsInfo.xml"));
        var com = from committee in xmlDoc.Descendants("news")
                  select new
                  {
                      id = committee.Element("id").Value,
                      title = committee.Element("title").Value,
                      link = committee.Element("link").Value,
                  };
        DataTable dt = getTable();
        foreach (var c in com)
        {
            DataRow dr = dt.NewRow();
            dr["id"] = c.id;
            dr["title"] = c.title;
            dr["link"] = c.link;
            dt.Rows.Add(dr);
        }
        return dt;
    }
    protected DataTable getTable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("id");
        dt.Columns.Add("title");
        dt.Columns.Add("link");
        return dt;
    }
    protected void fillgrid()
    {

        ASPxGridView1.DataSource = retriveDetailsFromXML();
        ASPxGridView1.DataBind();
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        ASPxGridView1.AddNewRow();
    }
    protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
            DataTable dt = retriveDetailsFromXML();
            XDocument doc = XDocument.Load(Server.MapPath("~\\Data\\newsInfo.xml"));
            doc.Element("newsInfo").Add(new XElement("news", new XElement("id", Convert.ToInt32(dt.Rows[dt.Rows.Count - 1][0]) + 1), new XElement("title", e.NewValues[0]), new XElement("link", e.NewValues[1])));
            doc.Save(Server.MapPath("~\\Data\\newsInfo.xml"));
            fillgrid();
        
        ASPxGridView1.CancelEdit();
        e.Cancel = true;

    }
    protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {

        if (Session["KeyValue"] != null)
        {
            Int32 key = Convert.ToInt32(Session["KeyValue"]);
            XDocument doc = XDocument.Load(Server.MapPath("~\\Data\\newsInfo.xml"));
            IEnumerable<XElement> com = doc.Elements("newsInfo").Elements("news");
            var oCom = (from member in com
                        where member.Element("id").Value == key.ToString()
                        select member).SingleOrDefault();
            oCom.SetElementValue("title", e.NewValues[0]);
            oCom.SetElementValue("link", e.NewValues[1]);
           
            doc.Save(Server.MapPath("~\\Data\\newsInfo.xml"));
            Session["KeyValue"] = null;
        }
        fillgrid();


        ASPxGridView1.CancelEdit();
        e.Cancel = true;

    }
    protected void ASPxGridView1_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
    {
        Session["KeyValue"] = Convert.ToInt32(ASPxGridView1.GetRowValuesByKeyValue(e.EditingKeyValue, "id"));
    }
    protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
    {
        XDocument doc = XDocument.Load(Server.MapPath("~\\Data\\newsInfo.xml"));
        doc.Element("newsInfo").Elements("news").Where(x => x.Element("id").Value.Trim() == e.Keys["id"].ToString()).Remove();
        doc.Save(Server.MapPath("~\\Data\\newsInfo.xml"));
        fillgrid();

        e.Cancel = true;
    }

Can any 1 tell me wat is problem.
Posted

I haven't looked at your code,
but the obvious question that comes to mind is....

Do you have WRITE access for the folder on the server?
 
Share this answer
 
Comments
Hetal Jariwala 8-Dec-12 6:22am    
How can i check that??
Zaf Khan 8-Dec-12 6:40am    
When and IF you change the READ/WRITE acces permission.
Make SURE it is ONLY for YOU and not for EVERYONE!!!!!!
Surendra0x2 8-Dec-12 6:46am    
Exactly :)
Hetal Jariwala 8-Dec-12 7:25am    
tnx guys
it's solved
shaikh-adil 12-Dec-12 2:14am    
HIi am makinng a windows form project and facing
difficulty in passing the dnamically generated
control value to the other form's normal control
value.
my code is like
i n t c = 0 ;
i n t p = 0 ;
p r i v a t e v o i d b u t t o n 1 _ C l i c k ( o b j e c t s e n d e r , E v e n t A r g s e )
{
p a n e l 1 . V e r t i c a l S c r o l l . V a l u e = V e r t i c a l S c r o l l . M i n i mum ;
C omb o B o x t x t R u n 3 = n ew C omb o B o x ( ) ;
t x t R u n 3 . N ame = " t x t D y n am i c " + c + + ;
t x t R u n 3 . L o c a t i o n = n ew P o i n t ( 3 0 , 1 8 + ( 3 0 * c ) ) p a n e l 1 . C o n t r o l s . Ad d ( t x t R u n 3 ) ;
t x t R u n 3 . F o c u s ( ) ;
}
p r i v a t e v o i d b u t t o n 2 _ C l i c k ( o b j e c t s e n d e r , E v e n t A r g s e )
{
F o r m4 f 4 = n ew F o r m4 ( ) ;
C omb o B o x c b 1 = s e n d e r a s C omb o B o x ;
B u t t o n b s = c b 1 . T a g a s B u t t o n ;
f 4 . c omb o B o x1 . T e x t = b s . T e x t ;
f 4 . S h ow ( ) ;
}
i am getting error as
"Object reference not set to an instance of an
object."
Use This Link-
http://www.activeservers.com/Set-Perms-Cuteftp.aspx[^]

and change Folder permission
mark answer as Solution if this works for you. :)
 
Share this answer
 
Comments
Hetal Jariwala 8-Dec-12 6:42am    
For uploding image am i suppose to change permission for the folder??
Surendra0x2 8-Dec-12 6:46am    
Yes if on Server then You Have to Change Folder permission :)
Try to change the Read/write Permission of Folder where you're saving your file.
i also faced problem when i was uploading Image in the folder then it was throwing Access is denied Exception
so i changed the Read/Write Permission of Folder where you're uploaded File is going to save.
 
Share this answer
 
Comments
Hetal Jariwala 8-Dec-12 6:23am    
How can i do that??
I'm using cute ftp.
Surendra0x2 8-Dec-12 6:27am    
In My Case i'm using Godaddy Hosting here

select the Folder and Click on Permissions then i can change read/write permission
but in ur case i dnt know how to do this coz may be ur hosting server would be different.
Surendra0x2 8-Dec-12 6:30am    
use this link-
http://www.activeservers.com/Set-Perms-Cuteftp.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900